How to Fix a Hacked WordPress Site
Contain, find, clean, close the hole, monitor. Verify core and plugins against WordPress.org checksums, then check the places checksums cannot see: uploads, mu-plugins, drop-ins, wp-config.php, users, options and cron.
The fix is a sequence, not a scan: contain the site, verify core and plugins against WordPress.org checksums, check the places checksums cannot see, clean, close the entry route, and only then rotate every credential.
Do the steps in this order. Rotating passwords while a backdoor is still running only hands the attacker the new ones; cleaning without closing the hole gets you reinfected within days.
1. Contain
- Put the site behind maintenance mode or ask the host to block public traffic.
- Copy the current files and database before changing anything, and label the copy as infected. It is your evidence, and the only way back if cleaning breaks something.
- On a store, look for fraudulent orders and pause payments if anything looks manipulated.
- If other sites share the hosting account, treat them as infected too. Cleaning one while its neighbour stays dirty achieves nothing.
2. Find: verify what can be verified
WordPress.org publishes an MD5 checksum for every file in every core release; core reads the same list itself through get_core_checksums(). With WP-CLI you can compare the whole install in one command:
wp core verify-checksums
wp plugin verify-checksums --all
The core check lists files that do not match and extra files sitting in core folders. The plugin check only works for plugins hosted on WordPress.org; premium plugins have nothing to compare against, so reinstall those from the vendor instead of trusting them.
On a WordPress 7.1.5 test install with one byte appended to a core file and an extra file dropped into wp-includes under a plausible name:
$ wp core verify-checksums
Warning: File doesn't verify against checksum: wp-includes/version.php
Warning: File should not exist: wp-includes/class-wp-cache-helper.php
Error: WordPress installation doesn't verify against checksums.
$ wp plugin verify-checksums --all
Success: Verified 4 of 4 plugins.
The extra file has a name that looks like it belongs to core; only the checksum comparison exposes it.
Checksums cover wp-admin, wp-includes, the root core files and repository plugins. Everything below is outside that net, and that is where malware usually lives.
Where malware hides, and how to check each place
| Location | What attackers put there | How to check | Clean-up |
|---|---|---|---|
wp-content/uploads/ |
PHP shells disguised as images or cache files | find wp-content/uploads -type f -name '*.php' |
Delete every PHP file; keep the media |
wp-content/mu-plugins/ |
A "must-use" backdoor: loads on every request, needs no activation, cannot be deactivated from the dashboard | Plugins → Must-Use tab, or Tools → Site Health → Info → Must Use Plugins | Delete anything you did not install |
Drop-ins in wp-content/ |
db.php and object-cache.php load automatically on every request; advanced-cache.php loads when WP_CACHE is true; maintenance.php, db-error.php, php-error.php, fatal-error-handler.php run in their own situations |
Plugins → Drop-ins tab, or Site Health → Info → Drop-ins | Delete, then let your real cache plugin regenerate its file |
wp-config.php |
include of a hidden file, injected code above the opening comments, changed DB credentials |
Read it top to bottom; compare with wp-config-sample.php |
Rebuild from the sample plus your known values |
.htaccess, .user.ini, root index.php |
Redirect rules keyed on referrer or user agent; auto_prepend_file; code before require in index.php |
Compare with the default .htaccess and a fresh index.php |
Replace with clean copies |
| Users | Extra administrators, often with plausible names | wp user list --role=administrator or Users → Administrator filter |
Delete them (assign content to a real user) |
wp_options |
siteurl/home pointing elsewhere, an extra entry in active_plugins, users_can_register on with default_role set to administrator |
wp option get siteurl, wp option get active_plugins --format=json, Site Health → Info → WordPress |
Reset values; deactivate unknown entries |
| WP-Cron | A scheduled event that re-downloads the malware after you delete it | wp cron event list |
Delete hooks that belong to no installed code |
Two details from core are worth knowing. Since WordPress 7.0 the New User Default Role dropdown in Settings → General hides Administrator and Editor unless one of them is already the saved value, so seeing Administrator there means someone wrote it directly. And Site Health reports the combination as a critical issue: "Open Registration with privileged default role".
The usual "files change back after I clean them" problem is almost always a must-use plugin, a drop-in or a cron event from this table.
3. Clean: replace rather than repair
- Core. Delete
wp-adminandwp-includes, then upload them from a fresh download of the same version. Delete first, so extra files cannot survive a merge. - Plugins and themes. Delete each one and reinstall from WordPress.org or the vendor. Anything you cannot get a clean copy of, remove. Nulled plugins are malware by design.
- Uploads. Keep the folder; remove anything executable.
- Database. Search
wp_postsfor injected<script>and<iframe>tags, and clean the options, users and cron events from the table above.
If the dashboard is unusable while you work, disable plugins without admin access by renaming folders over SFTP.
4. Close the hole
The usual entry routes, roughly in order of frequency:
- an outdated plugin or theme with a published vulnerability;
- a reused or leaked administrator password;
- stolen SFTP or hosting credentials, often from an infected local computer;
- a compromised neighbour site on the same hosting account.
Read the access log around the timestamp of the earliest malicious file. Update everything, remove plugins you do not use, and set DISALLOW_FILE_EDIT so a stolen admin login cannot edit PHP from the dashboard.
5. Rotate credentials, in this order
Now that nothing malicious is running, revoke access:
- Salts. Run
wp config shuffle-saltsor replace the eightAUTH_KEY…NONCE_SALTconstants inwp-config.php. Every login cookie becomes invalid, for everyone. - Passwords. Reset every administrator and editor password. A password change also invalidates that user's cookies, because the cookie contains a fragment tied to the password hash.
- Application Passwords. Neither salts nor password changes touch them. On each user's profile, under Application Passwords, click Revoke all application passwords.
- Sessions. On your own profile the Sessions row shows Log Out Everywhere Else when you are logged in somewhere else too; on another user's profile the button is Log Out Everywhere.
- Outside WordPress. Database password (then
wp-config.php), hosting panel, SFTP, SSH keys, and API keys for payments and email.

6. Monitor
- Run both checksum commands again after a day and after a week.
- Re-run
wp cron event listand look at the Must-Use and Drop-ins tabs once more. Anything reappearing means a backdoor survived. - Request a search engine review only once the site is clean. Spam URLs should return 404 or 410, not redirect.
- Keep updates current, with automatic core updates at least for minor releases.
Common mistakes
- Demoting rogue admins instead of deleting them. The account and its Application Passwords remain.
- Restoring a backup without knowing the infection date. The backup may already contain the backdoor.
- Deleting
object-cache.phporadvanced-cache.phpyou actually use. Confirm against your cache plugin, then let it regenerate the file rather than keeping an unknown copy.
Frequently asked
- Only if the backup predates the compromise and you also close the hole that let the attacker in. Restoring onto the same vulnerable plugin, or with the same stolen password and Application Passwords still valid, gets the site reinfected.
- It invalidates login cookies issued for that account, because the cookie is tied to the stored password hash. It does not revoke Application Passwords, and it does nothing about other admin accounts or a backdoor file. Rotate the salts, revoke Application Passwords and review every administrator as well.
- Take the modification time of the earliest malicious file you found and read the web server access log around it. A POST to a plugin endpoint, an upload, or a login from an unknown address just before that moment usually points to the entry route.