Blog / Web management /
How I handle a hacked WordPress site
The message usually arrives sounding like this: “Our site is showing Japanese characters in Google.” Or: “Customers say the site sent them somewhere weird.” Or the worst one, from a browser: a full red warning page telling visitors the site is dangerous.
A hacked site is one of the few website problems where speed genuinely matters. Every hour it stays infected, more visitors get redirected, more spam pages get indexed, and the cleanup in search gets longer. But speed isn’t the same as rushing. Deleting files at random and reinstalling plugins in a panic is how you end up hacked again next week.
So I work through the same order every time. It’s the part of looking after several client sites where having a written process matters most, because nobody thinks clearly with a red warning screen in front of them.
Step 1: contain it
Before investigating anything, stop the damage spreading.
- Take a full backup of the hacked site. Yes, the infected one. Files and database. You need it to work out what happened, and if a cleanup goes wrong you’ll want to compare.
- Put the site into maintenance mode if it’s redirecting visitors or serving malware. A plain holding page is better than sending customers to a scam.
- Change the passwords that matter: hosting control panel, SFTP, database, and every WordPress administrator. Do it from a clean device.
- Tell the client what’s happening in plain language, and what you need from them (usually host access, and whether anyone else has logins).
That last step is easy to skip when you’re busy. Don’t. A client who hears “we’ve found it, the site’s safe while we work on it” handles the next few hours much better than one who finds out from a customer.
Step 2: work out how far it goes
Hacks rarely stay in one file. Before cleaning, I want a picture of everything that’s been touched.
Check what’s been added
- Admin users. Look at Users → filter by Administrator. An account you don’t recognise is a strong sign, and attackers often create one to get back in.
- Recently modified files. Through SFTP or the host’s file manager, sort by date. PHP files changed in the last few days in
wp-content/uploads/should never be there at all. - Unknown plugins or “must-use” plugins in
wp-content/mu-plugins/that nobody installed. - Code in
wp-config.php,.htaccessand theme files that looks scrambled: long encoded strings,eval,base64_decode.
Check what Google can see
- Search
site:yourdomain.comand look for pages you never published, often spam in another language. - Open Search Console → Security issues. If Google has detected the hack, it’ll say so here, sometimes with example URLs.
- Use the URL Inspection tool on a few key pages and look at the rendered HTML. Some hacks only show their spam to Googlebot, not to people visiting normally.
Run a scanner, but don’t trust it alone
A security plugin’s malware scan or the host’s scanner helps find the obvious files. It won’t find everything, and it can’t tell you how the attacker got in. Treat it as a second opinion.
Step 3: clean it
My preferred cleanup is replacement, not repair:
- Reinstall WordPress core from a fresh download. Core files should never be custom, so replacing them is safe.
- Reinstall every plugin and theme from the official source, rather than trying to clean the existing copies. If a premium plugin can’t be redownloaded, that’s worth knowing for the future.
- Delete anything that shouldn’t be there: unknown plugins, PHP files in uploads, the mystery admin user.
- Clean the database. Look for injected scripts in posts, widgets and the
wp_optionstable (especiallysiteurl,homeand anything autoloaded with odd code). This is the slow part. - Keep the content. The uploads folder (minus any PHP) and the database content are what matter to the client. Everything else can be replaced.
When to restore a backup instead
If there’s a clean backup from before the infection, restoring it can be faster. Two catches: you need to be sure the backup really is from before the hack started (they often begin weeks before anyone notices), and restoring brings back the same hole the attacker used. A restore without step 4 is just resetting the clock.
This is where good backups pay for themselves. I set out the setup I’d want in WordPress backups: a setup that saves you on the worst day.
Step 4: close the hole
Cleaning a site without knowing how it was hacked is mopping the floor while the tap’s still running. The usual ways in:
- An outdated or abandoned plugin with a known vulnerability. By far the most common. I wrote about spotting abandoned plugins for exactly this reason.
- A nulled (pirated) theme or plugin that came with a backdoor built in.
- Weak or reused passwords, with no two-factor login.
- Another site on the same hosting account. One infected site in a shared cPanel account can reach the others.
- Old admin accounts belonging to former staff or an old agency.
Check the server access logs if the host keeps them, the dates of modified files, and the plugin list against known vulnerabilities. Then fix it: update or remove the plugin, remove old accounts, turn on two-factor login, and separate sites that share an account.
Afterwards, tighten the basics: file editing disabled in the dashboard, XML-RPC locked down if it isn’t needed, a firewall in front where it makes sense. There’s more on that in XML-RPC, the REST API and what to lock down on WordPress.
Step 5: tell Google and clean up search
Once the site is clean and the hole is closed:
- Request a review in Search Console’s Security issues report, if Google flagged the site. Explain briefly what you found and fixed. Reviews for hacked sites are usually faster than for manual actions, but it’s not instant.
- Deal with the spam URLs. If the hack created thousands of junk pages, make sure they now return a 404 or 410. Google will drop them as it recrawls. For the most visible ones, the Removals tool can hide them from results temporarily while that happens.
- Resubmit the sitemap so Google recrawls the real pages first.
- Check the site isn’t still blocklisted elsewhere: some browsers and security services keep their own lists.
The spam URLs can linger in Search Console’s reports for weeks. That’s annoying but normal, and it doesn’t mean the site is still hacked.
Step 6: write it down
Last, the change log. What happened, when it was found, how they got in, what was replaced, which passwords were changed and what’s been tightened. If anything odd shows up in the following weeks, that record is where you start. I explain why I keep one for every site in change logs for websites: why I write down every fix.
I also set a reminder to rescan the site a week later. Attackers who left a second backdoor tend to use it.
What actually prevents most hacks
Nothing here is clever. Most WordPress hacks come through the same few basics:
- plugins and themes kept updated, and abandoned ones replaced
- no nulled software, ever
- unique passwords and two-factor login for every administrator
- an access review that removes people who’ve left
- backups stored away from the server, and tested
Boring, and that’s the point. Every one of these is cheaper than a cleanup.
Related reading
- WordPress security basics every site owner should know
- WordPress backups: a setup that saves you on the worst day
- Abandoned WordPress plugins: spotting the ones nobody maintains
- XML-RPC, the REST API and what to lock down on WordPress
If you look after a WordPress site, write your own version of this list before you need it, and put the hosting login somewhere you can find it on a bad morning. Do you know right now where your last clean backup is?