WordPress site hacked? A calm step-by-step recovery plan
Spam pages, strange redirects or a browser warning are alarming, and recoverable. Work through these steps in order and resist the urge to start deleting things.
Discovering your WordPress site hacked is a bad moment. A customer rings to say your website sent them to a gambling page. Google shows a red warning in front of your home page. Your host emails to say the account has been suspended for sending spam. The instinct is to log in and start deleting whatever looks wrong.
Take a breath first. WordPress’s own documentation for this situation includes the instruction to stay calm, and it is sound advice, because hurried deletions destroy the evidence you need and frequently miss the actual cause. A compromised site can almost always be recovered. This guide gives you the order to work in. It covers response and recovery only; for the prevention side, see our website security checklist. And if you would rather hand the incident to someone, recovery and the upkeep that prevents a repeat are both part of our WordPress maintenance service.
A WordPress site hacked once is far less likely to be hacked again if you close every door this guide covers, not just the one that was used this time.
Signs of a compromise
Hacked sites do not always look hacked to their owners. Attackers often hide their work from logged-in administrators and show it only to search engines or first-time visitors. Signs to take seriously:
- Redirects. Visitors, particularly on phones or arriving from Google, are sent to unrelated sites.
- Content you did not create. New pages, posts or links, often about pharmaceuticals, gambling or counterfeit goods. Search Google for site: followed by your domain and look for titles you do not recognize.
- Warnings. A browser warning page, or a label in Google’s results. Google’s Search Console documentation says affected pages may show a warning label in search results, or a browser may display a warning when someone tries to visit.
- Unknown users. Administrator accounts nobody on your team created.
- A notice from your host about malware, spam email or unusual resource use.
- Search Console alerts. Google’s Security issues report lists what it has found, in three groups: hacked content, malware and unwanted software, and social engineering.
- Strange files or changed code, unexpected pop-ups, or the site suddenly running very slowly.
Not every oddity is an attack. A failed update, an expired certificate or a plugin conflict can also break a site. The steps below help you confirm which it is.
WordPress site hacked: the first hour
The goals for the first hour are to stop harm to visitors, preserve evidence and avoid making things worse. Cleaning comes later.
- Write down what you see. WordPress’s guidance is to document: what the symptoms are, what time you noticed and in which time zone, and what changed recently, such as a new plugin or a theme edit. Take screenshots.
- Call your hosting provider. Ask whether they can see the compromise, whether other sites on the account or server are affected, and what backups they hold. WordPress’s documentation recommends checking with your host, partly to establish whether it is a real hack or a loss of service.
- Take a copy of the site as it is now. Files and database, infected or not. It feels wrong to back up a hacked site, but WordPress’s guidance specifically recommends a snapshot of the current environment before cleaning. It is your evidence, and your safety net if a cleanup goes badly.
- Put the site into maintenance mode or take it offline if visitors are being redirected or served malware. A short outage is better than infecting your customers.
- Do not delete things yet. Removing the one suspicious file you can see leaves the hidden ones in place and erases the dates and details that show how the attacker got in.
- Scan the computers that have access. WordPress recommends a full anti-malware scan of your local machine. If a password was stolen from an infected laptop, changing it on that same laptop gives the new one away.
- Change the most critical passwords now, from a clean device: hosting control panel, WordPress administrators, and the email account that receives password resets.
If the site takes payments or stores personal information about customers, you may have legal or contractual duties to notify people or your payment provider. That depends on what data was involved and where you operate, and it is a question for your attorney and your payment processor, not something this article can answer.
Restore from backup or clean in place
There are two routes back to a clean site. Which is right depends on your backups.
Restoring a backup
This is usually the faster and more certain route, with conditions:
- The backup must predate the compromise. Attackers often get in weeks before anything visible happens. A backup from last night may contain the same hidden files. Use your notes, file dates and the host’s logs to estimate when it started, and choose a copy from before then.
- You will lose what changed since. Orders, form entries, new posts, comments. For a brochure site that changes rarely, this is minor. For a store, it may rule this route out or mean exporting recent orders first.
- A restore puts the old weakness back too. The site that was hackable a month ago is hackable again the moment it is restored. Update everything and reset access immediately afterwards.
Cleaning in place
If there is no trustworthy backup, the site has to be cleaned where it stands. In outline, following WordPress’s documentation:
- Scan the site with a reputable security scanner to locate malicious files and database entries. Scanners find a great deal, though not always everything.
- Replace WordPress core files with fresh copies of the same version from WordPress.org. WordPress recommends replacing the wp-admin and wp-includes folders over SFTP, not by using the reinstall button inside the dashboard.
- Replace every plugin and theme with a fresh copy from its original source. Delete any you do not use, and any you cannot identify.
- Inspect what cannot be replaced: the uploads folder, which should not contain program files, and the files WordPress singles out for checking, including .htaccess, index.php and the theme’s header, footer and functions files.
- Check the database for injected content, unfamiliar administrator users and altered settings such as the site address.
- Look for scheduled tasks and extra files the attacker left to let themselves back in.
Cleaning by hand is detailed work, and missing one backdoor means the infection returns within days. It is reasonable to do yourself if you are comfortable with files and databases. If not, this is the step to hand to a professional.
Passwords, users and keys
Assume every credential connected to the site is known to the attacker. Once the site is clean, reset all of them, from a device you have scanned.
- WordPress users. Remove accounts you do not recognize. Force a password reset for everyone, administrators first. Reduce the number of administrators to those who truly need it.
- Hosting and file access. Control panel, SFTP or FTP accounts, and SSH keys. Delete accounts nobody uses.
- The database password, updating the configuration file to match.
- WordPress secret keys. WordPress recommends replacing the secret keys in the configuration file with new ones from its key generator. This logs out anyone still signed in, including an attacker holding a stolen session.
- Connected services. API keys for email delivery, payment gateways, backups and other integrations stored on the site.
- Email accounts used for password resets.
- Turn on two-factor authentication for administrators.
WordPress’s guidance is to change the passwords again once you have confirmed the site is clean. It sounds excessive. It is not: passwords changed while a backdoor was still present may have been captured.
Getting warnings removed from Google
If Google flagged the site, the warning does not disappear by itself the moment you finish cleaning. You have to ask for a review.
- Verify the site in Google Search Console if you have not already. WordPress’s documentation also recommends registering with search engines’ webmaster tools for this reason.
- Open the Security issues report. Read each issue’s description and use the sample URLs Google provides to find affected pages.
- Fix every issue on every page. Google’s instruction is to fix the issue throughout your site, not only on the sample pages, and then test.
- Select Request Review. Google asks you to explain what the problem was, what you did to fix it and the result. Be specific and factual.
- Wait. At the time of writing, Google’s Search Console help says reviews usually take several days to several weeks, and that resubmitting while a request is pending can slow things down.
Also remove what the attacker left in Google’s results. Spam pages that have been deleted should return a not-found response so they drop out of the index, and it is worth checking the Manual actions report as well. If your host suspended the account or your domain was listed on email blocklists, each of those has its own request process once you can show the site is clean.
Search visibility can dip during an incident and usually recovers after the warnings are lifted, but nobody can promise when or to what level. That decision is Google’s.
Closing the door afterwards
A cleaned site with the same weakness is a site waiting to be hacked again. Before you call the incident closed:
- Find the entry point if you can. An outdated plugin with a known vulnerability, a reused password, an abandoned theme, an infected neighbour on the same hosting account. Logs and file dates help.
- Update everything. WordPress core, every plugin, every theme, and the PHP version on the server.
- Remove what you do not use. Inactive plugins and themes can still be attacked.
- Replace abandoned plugins that no longer receive updates.
- Add a firewall and monitoring so the next attempt is blocked or at least noticed quickly.
- Fix backups. Daily, stored away from the server, kept for long enough to reach back before a slow-burning compromise, and tested by actually restoring one.
- Review your hosting. If the host could not help, held no backups or runs outdated software, consider moving. Our website maintenance and hosting page describes what managed hosting should include.
- Watch closely for a month. Re-scan weekly and check Search Console. Reinfection usually shows up early.
Most compromises we are called in on trace back to a site nobody was maintaining. Our article on what happens to an unmaintained WordPress site shows how that builds up over a year, and our website and application security page covers hardening in more depth.
When to get help
Handle it yourself if you have a clean, recent backup, a simple site, and a host who is responsive. Get help if the site takes payments or holds customer data, if you have no backup you trust, if the infection came back after a cleanup, or if you simply do not have the hours to do this carefully. No one can promise that a site will never be attacked again; what good maintenance does is shrink the opportunity and shorten the time before a problem is noticed.
We have looked after WordPress sites for local businesses for more than ten years. If your site has been compromised, we can assess it, recover it and put the updates, backups and monitoring in place that make a repeat far less likely. See our WordPress maintenance page, or contact us and tell us what you are seeing.
Frequently asked questions
How do I know if my WordPress site was hacked?
Common signs are visitors being redirected to unrelated sites, pages or links you did not create, a browser or Google warning that the site may be harmful, administrator accounts you do not recognize, a notice from your host, or security issues reported in Google Search Console. One sign alone can have an innocent cause, so confirm with a scan and your host before acting.
Should I restore a backup or clean the site?
Restore if you have a backup you are confident was taken before the compromise and you can afford to lose what changed since. Clean in place if there is no trustworthy backup or the site changes daily, as a store does. Either way, the weakness that let the attacker in must be fixed afterwards or the site will be reinfected.
Will a hack hurt my Google rankings?
It can while the problem lasts. Google says security issues may affect a site’s presence in search, and that affected pages may show a warning label in results or trigger a browser warning before people can visit. Once the site is clean you can request a review in Search Console. Nobody can promise how quickly visibility returns.
How did they get in?
The usual routes are an outdated plugin or theme with a known vulnerability, a weak or reused password, a compromised computer belonging to someone with access, an abandoned plugin, or another infected site on the same hosting account. Server logs and file dates often point to the answer, though sometimes it cannot be established with certainty.
How do I stop it happening again?
Keep WordPress, plugins and themes updated, remove anything unused, use strong unique passwords with two-factor authentication, limit administrator accounts, keep daily backups stored away from the server and tested, use reputable hosting with a firewall, and monitor the site so problems are caught early.