How to Clean a Hacked WordPress Site

WordPress hacked site cleanup with shield and scanner

This guide starts where our hacked-signs guide ends. It assumes you have already confirmed the hack — if you are still unsure, read that guide first and run its checks. Cleaning has an order: back up first, lock access, find what is infected, replace it, then update and ask Google to re-check. Skipping ahead is how sites get hacked twice.

One warning before you start: do not delete files or database rows you do not recognise on a guess — a wrong delete can break the site worse than the hack did. If your host has already suspended the site, work with them.

1. Take a snapshot first

Before you clean anything, make a copy of the site as it is right now — infected and all. Ask your host if they keep backups, and take one yourself too: files plus the database. You need it for two reasons: if a cleaning step goes wrong, you can go back — and the infected copy is your evidence for working out how the attacker got in later.

Do not overwrite your last clean backup with this one — keep the two separate and labelled.

2. Lock the doors

A hack means someone has access. Before you clean, stop them using it again.

Change the passwords for WordPress admin, your hosting account, FTP or SFTP, and the database user — for every user with access, not just your own account. Use long, unique passwords; a password manager’s generator is the easiest way to make them.

Then force everyone out: in wp-config.php, replace the eight secret keys and salts with fresh values from the WordPress key generator (api.wordpress.org/secret-key/1.1/salt/). New keys log out every session at once, including the attacker’s.

Finally, in Users, remove any administrator account you do not recognise — attackers often add a hidden admin so they can walk back in after you clean.

3. Scan to find what is infected

Guessing which files are infected wastes time. Scan first, clean second.

Install a security plugin with a scanner and run a full scan: Wordfence (free, on wordpress.org) includes a malware scanner, and the free Sucuri Security plugin includes file integrity monitoring, which flags changed files. Run one scanner, not two — two mostly argue with each other.

Also run a remote scan, which sees the site the way a visitor does: Sucuri SiteCheck (sitecheck.sucuri.net) and VirusTotal (virustotal.com) catch injected content and redirects a plugin scan can miss.

And scan your own computer: WordPress.org’s hacked-site guidance says the attack often starts on the owner’s machine, where malware steals FTP and wp-admin logins. Run a full antivirus scan on every computer you use to log in.

Write down what the scans find — which files, which database entries, which URLs.

4. Restore or replace the files

A clean backup from before the hack is usually the fastest route — but only if you know it is from before the hack. If you are not sure when the hack happened, do not restore blindly: the backup may already be infected.

Without a clean backup, replace the files by hand: download a fresh copy of WordPress (the same version your site runs) and replace the wp-admin and wp-includes folders over SFTP. Do not use the reinstall option inside wp-admin — it only overwrites existing files, and hacks often add new ones that an overwrite leaves behind.

Then reinstall every theme and plugin from a clean source — wordpress.org for free ones, the vendor for paid ones. Delete anything you do not use, and any file the scan flagged that you cannot account for.

Check by hand the most common targets: .htaccess in the site root (attackers hide redirects in it), and index.php, header.php, footer.php and functions.php in your theme. If your site redirects visitors to spam, our spam-redirect guide walks through how to find the source.

5. Clean the database

Files are only half the hack. Injected links and scripts also live in the database, and a file-only cleanup leaves them behind.

In wp-admin, check Posts and Pages for pages you did not create, and the menu for links you did not add. Then check the database itself — your host usually provides phpMyAdmin. In wp_options, look for suspicious entries (especially siteurl, home, and any option holding scripts or links), and search wp_posts for spam words and script tags that should not be there.

Remove what the scan flagged and what you can see is injected. Do not run a bulk find-and-replace on the whole database unless you know exactly what you are replacing — a wrong replace can break every post at once.

6. Update everything

Once the site is clean, update it. Outdated software is the most common way in: update WordPress core to the latest version (7.1.5 at the time of writing — check for a newer one first), then update every theme and plugin.

Turn on auto-updates for plugins and themes you trust, and let WordPress handle minor core updates itself — our auto-updates guide explains which updates are safe to leave automatic. Delete the themes and plugins you do not use instead of leaving them installed and out of date: unused software is still an open door.

7. Change every password again

You changed the passwords in step 2 — change them again now that the site is clean.

WordPress.org’s own guidance is explicit: change them after you are sure the site is clean, because passwords changed while the hack was still active may already be stolen. So change the WordPress admin, hosting, FTP/SFTP, and database passwords a second time, with fresh unique values. If you use two-factor authentication, keep it on — or set it up now.

8. Check the blacklists and ask Google to re-check

If Google flagged the site, cleaning the files does not clear the flag by itself. Open Google Search Console, go to Security & Manual Actions, then Security issues, and read what Google found — the issue type and the sample URLs. The samples are only a sample: clean the whole site, not just the listed pages.

When every issue is fixed across the whole site, click Request review in that report and describe what you fixed: the problem, what you removed, and how you closed the entry point. Reviews take several days to a few weeks, and you should not resubmit while one is pending — it can make the next review take longer. Check the other blacklists too, and re-check on VirusTotal until it comes back clean.

9. Find how they got in, then close it

Cleaning without finding the entry point is how a site gets hacked again the next week. Work out the cause: check your host’s access logs around the date the hack first appeared, list which plugins and themes were out of date, and check who had admin access.

Then close it: run through our hardening checklist — strong passwords, two-factor authentication, limited login attempts, and correct file permissions (644 for files, 755 for folders, wp-config.php locked down further). Our file-permissions guide explains the numbers, and our DIY security audit checklist gives you the same checks as a routine.

When to get help

If the site is still redirecting after you replaced the files, if new infected files keep appearing, or if you cannot log in at all, stop and get help. Your host may offer a malware cleanup service, and the free WordPress.org hacked and malware forums are a good place to ask — describe your symptoms, what the scans found, and what you already tried.

Can I just restore a backup and be done?

Only if the backup is from before the hack — if you do not know when the hack happened, the backup may already contain it. Even after a clean restore, change all passwords, update everything, and scan again.

Will reinstalling WordPress delete my content?

No. Your posts, pages, and media live in the database and in wp-content/uploads, which replacing wp-admin and wp-includes does not touch. Back up first anyway — a mistake during cleanup is much harder to undo without one.

How do I know the site is really clean?

Scan again after cleaning and get a clean result, then watch for a few days: no new unknown files, no new admin users, and the scans stay clean. A passed Google review in Search Console is the outside confirmation.

How long does Google take to remove the warning?

Google’s own estimates are a few days for malware and up to several weeks for hacked spam, counted from a successful review. Do not resubmit while one is pending.

My host suspended my site — can I still clean it?

Work with your host — they can usually give you file access or restore a backup even while the site is suspended. Do not try to work around it: the suspension is there to stop the hack spreading.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *