Skip to content
Blog Security

WordPress Site Hacked? A Calm, Step-by-Step Recovery Plan

It usually starts with a message you don’t want to read. A client writes that their site “looks weird on the phone.” Google shows a red warning instead of the home page. Or you open the site yourself and land on a casino page you definitely didn’t build. Your heart rate goes up, and the urge is to start deleting things. Don’t. A hacked WordPress site is fixable, and almost every time we’ve seen a recovery go wrong, it’s because someone rushed the first hour. This is the order we work in when a site is hacked. It’s not the only way, but it’s the one that has cleaned the most sites for us with the fewest surprises a week later.

How to tell your WordPress site has been hacked

Some hacks are loud. Most are quiet, because the attacker wants your site’s reputation, not your attention. Look out for:
  • Redirects to spam, pharmacy or casino sites — often only on mobile, or only for visitors coming from Google, so you don’t notice them yourself.
  • Strange search results: Japanese or pharma keywords under your domain when you search site:yourdomain.com.
  • Browser or Google warnings such as “This site may be hacked” or “Deceptive site ahead.”
  • New administrator accounts nobody remembers creating, or an admin that doesn’t show up in the user list at all.
  • Files that shouldn’t be there: random PHP files in the uploads folder, or core files with today’s date.
  • A sudden slowdown, a hosting warning about high CPU, or your server sending spam e-mail.
If you see even one of these, treat the site as compromised until you’ve proven otherwise.

The first hour: contain it

Step 1. Don’t wipe anything yet

It’s tempting to restore yesterday’s backup straight away. The problem is that you don’t know yet when the attacker got in. If it was three weeks ago, yesterday’s backup is infected too, and you’ll be doing this again on Friday. First take a full backup of the site as it is now, hacked and all. It’s evidence, and it’s your safety net if the clean-up goes wrong.

Step 2. Lock the doors

  • Put the site into maintenance mode, or block public access, so visitors and Google stop seeing the hacked version.
  • Change every password that touches the site: WordPress admins, hosting panel, FTP/SFTP, the database user, and the e-mail account linked to the admin user.
  • Log everyone out. Generating new security keys (salts) in wp-config.php ends every active session — including the attacker’s. WordPress has an official generator for them.
  • If you can, limit the admin area to your own IP address until the clean-up is done.

The first day: find out what happened

Step 3. Scan files and the database

Run a malware scan over the whole site, not just wp-content. Attackers like places people don’t look: the uploads folder (which should never contain PHP files), mu-plugins, the site root, and files named to look harmless like wp-cache.php or class-wp-mail.php. Don’t forget the database. Spam links and redirect scripts are often stored in posts, widgets or options rather than in files. Search the wp_options and wp_posts tables for <script, eval(, base64_decode and unfamiliar domains.

Step 4. Compare WordPress and plugins with the originals

WordPress publishes checksums for every core file, and for plugins hosted on WordPress.org. Comparing your files against them is the fastest way to spot what was changed. Anything modified or added that isn’t yours is a suspect. Replacing WordPress core with a fresh copy of the same version is safe and quick; just leave wp-config.php and wp-content alone while you do it.

Step 5. Hunt for back doors

Cleaning the visible damage isn’t enough. Attackers almost always leave a way back in, so if you miss it, the site gets re-infected within days. Check for:
  • Hidden administrators. Some back doors add an admin and hide it from the Users screen. Compare the number of administrators WordPress shows with what’s actually in the database.
  • Look-alike accounts such as admin1 or adrnin next to your real admin.
  • Changed server files: .htaccess, .user.ini and php.ini can load malicious code before WordPress even starts.
  • Scheduled tasks (WP-Cron events) that re-download the malware every hour.

Step 6. Work out how they got in

This step gets skipped the most, and it’s the one that stops a second hack. The usual suspects, roughly in order: an outdated plugin with a known vulnerability, a nulled (“free premium”) plugin or theme, a weak or reused admin password, and a forgotten file left in public, like an old backup zip or an installer script. The activity log and the dates on the infected files usually point to the culprit.

Clean it or restore it?

Now you can decide. If you have a backup from before the first sign of infection, restoring it is usually the cleanest option — then immediately update everything and close the hole you found in step 6. Otherwise you clean in place: remove the malicious files, reinstall plugins and themes from their original source, clean the database entries and delete every account you don’t recognise. Either way, delete anything you don’t use. Inactive plugins and spare themes are still code on your server, and still a way in.

The first week: win Google’s trust back

  1. Check Search Console. Open the Security issues report. If Google flagged the site, fix everything it lists, then request a review. Reviews often take a few days.
  2. Clean up spam pages. If the hack created thousands of spam URLs, make sure they return a 404 or 410 and remove them with the URL removal tool if they keep showing up.
  3. Check blacklists. Make sure the domain isn’t on spam or malware blacklists, and that your server isn’t flagged for sending spam mail.
  4. Tell the people who need to know. If customer data may have been exposed, your client may have legal duties to report it — under the GDPR in Europe, for example. Better to raise it early than have them find out later.

How to make sure it doesn’t happen again

Most hacks we clean up weren’t sophisticated. They were an old plugin nobody updated, or a password that was also used somewhere else. The fixes are boring, which is exactly why they get skipped:
  • Update plugins and themes every week — or automatically, with a rollback if an update breaks the site.
  • Use unique passwords and turn on two-factor login for every administrator.
  • Keep daily backups, several generations deep, stored somewhere other than the website’s own server.
  • Get alerted when something changes that shouldn’t: a new admin, a modified core file, a PHP file in uploads.
  • Remove anything you don’t use, and never install nulled plugins or themes.
If you look after many sites, doing all of this by hand is where things slip. That’s the reason we built Guard Core WP: it scans every site for malware and lets you quarantine files in one click, flags hidden admins, look-alike accounts, changed core files and modified plugins, checks each site from the outside for exposed files and blacklists, and keeps restorable backups — with a 24-hour undo if a restore isn’t what you expected. When something does go wrong, emergency lockdown closes the doors on a site in seconds. Want to see it on your own sites? Try it free for 14 days, no card needed.

Frequently asked questions

Can I just restore a backup to fix a hacked WordPress site?

Only if the backup was taken before the attacker first got in, and only if you also close the hole they used. Otherwise the site is either still infected or gets hacked again the same way. Keep a backup of the hacked state too, in case you need to investigate later.

Why does my WordPress site redirect to spam only on mobile?

Attackers hide redirects from site owners on purpose. The malicious code checks the visitor’s device, where they came from, or whether they’re logged in, and only redirects the visitors least likely to report it. Test in a private window on your phone, arriving from a Google search.

How long does it take to clean a hacked WordPress site?

A simple infection with a clean backup can be fixed in an hour or two. A deep infection with back doors in files and the database can take a day. Getting Google warnings removed usually adds a few days for the review.

Will my rankings come back after a hack?

Usually, yes, once the site is clean, the spam pages are gone and any Google warning has been lifted. The faster you act, the less lasting damage there is, which is why early alerts matter more than any clean-up tool.