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.
On this page
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
- Core: delete everything except
wp-contentandwp-config.php, and upload fresh WordPress files of the same version. - Plugins and themes: delete them all and reinstall fresh copies from official sources. Don’t keep old copies.
- Uploads: remove any
.phpfiles inwp-content/uploads— images never need them. How to find malicious files on your website - wp-config.php: compare line by line with a fresh
wp-config-sample.php. Look for unfamiliar code at the top or bottom. - 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?
- Recover a hacked website
Advanced · 120 min
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.
- My website has been hacked: what to doThe signs a site is compromised and a clear recovery order: contain, preserve, restore or clean, close the hole, and check search engines.
- Website redirecting to spam or scam sitesWhy a site redirects some visitors to spam, where the redirect code usually hides — .htaccess, PHP files, the database, JavaScript — and how to remove it.
- My email account is sending spamSigns a mailbox has been compromised, how to secure it, check for rules and forwarders an attacker added, and recover your sending reputation.
Spotted something out of date or unclear? Tell us and we’ll fix it.