How to clean a hacked WordPress site

A step-by-step recovery for a compromised WordPress site: contain it, restore or clean, close the way in, and check it’s clean afterwards.

Guide2 min readLast updated
On this page
  1. 1. Contain
  2. 2. Best option: restore a clean backup
  3. 3. No clean backup: rebuild the files
  4. 4. Close the way in
  5. 5. Check
  6. If it doesn’t work

Cleaning a hacked site properly takes a methodical approach. Removing only the visible symptom usually leaves a backdoor that reinfects the site.

1. Contain

  • Change passwords: DirectAdmin, database user, FTP, email and every WordPress administrator. Hosting account security checklist
  • Take a backup of the hacked site anyway, so you can recover content if the clean-up goes wrong. Mark it clearly.

2. Best option: restore a clean backup

If you have a backup from before the compromise, restore it, then go straight to step 4. Hunting through infected files by hand is slower and less reliable. Restoring website files and a database manually

3. No clean backup: rebuild the files

  1. Core: delete everything except wp-content and wp-config.php, and upload fresh WordPress files of the same version.
  2. Plugins and themes: delete them all and reinstall fresh copies from official sources. Don’t keep old copies.
  3. Uploads: remove any .php files in wp-content/uploads — images never need them. How to find malicious files on your website
  4. wp-config.php: compare line by line with a fresh wp-config-sample.php. Look for unfamiliar code at the top or bottom.
  5. Database: check Users for administrators you didn’t create, and search posts and options for injected <script> tags or unfamiliar domains.

4. Close the way in

  • Update everything, and remove plugins with known vulnerabilities
  • Replace WordPress salts (generate new ones with the official salt generator and paste into wp-config.php)
  • Disable file editing and block PHP in uploads How to secure a WordPress site

5. Check

  • Browse the site logged out, on mobile and from a search result — some malware only redirects visitors arriving from Google.
  • Scan with an external website malware scanner.
  • If Google flagged the site, request a review in Search Console once it’s clean.

Prefer to follow along?

If it doesn’t work

These guides cover the most common problems, starting with what you can see. Or browse every fix for a common problem.

Spotted something out of date or unclear? Tell us and we’ll fix it.

Keep going