Discovering your WordPress site has been hacked is one of the worst feelings for any website owner. You might see a defaced homepage, a Google warning, your hosting account suspended, or strange redirects sending visitors elsewhere. Whatever the symptom — the fix needs to happen fast.
In this guide, I'll walk you through exactly how to recover a hacked WordPress site, step by step. I've cleaned dozens of compromised WordPress installations over my 14+ years as a WordPress developer, and this is the same process I follow every time.
How Do You Know Your WordPress Site Is Hacked?
Common signs include:
- Your homepage is replaced with a defacement message
- Google Search Console shows a "This site may be hacked" warning
- Your hosting provider suspended your account for malware
- Visitors are being redirected to spam or phishing sites
- Google search results show spammy Japanese or pharmaceutical keywords under your domain
- You're locked out of wp-admin
- New admin users appeared that you didn't create
- Your site is extremely slow or sending spam emails
Even one of these signs means you need to act immediately.
Step 1: Put Your Site in Maintenance Mode and Back Up Everything
Before touching anything, take a full backup — even the infected files. You may need them later to compare what changed.
Connect to your server via FTP (FileZilla) or cPanel File Manager and download the entire public_html folder. Also export your database from phpMyAdmin.
Then put your site in maintenance mode so visitors don't hit the infected pages while you work. You can do this by adding a simple .htaccess redirect or placing a temporary HTML page.
Step 2: Scan for Malware
Use a trusted scanner to identify infected files before manually removing anything.
The best free options:
- Wordfence Security (free plugin) — run a full scan from wp-admin
- MalCare — deep scan, shows file-level changes
- Sucuri SiteCheck — paste your URL at sitecheck.sucuri.net for a quick external scan
- VirusTotal — upload suspicious files for multi-engine analysis
If you're locked out of wp-admin, install Wordfence via FTP by uploading the plugin folder directly to /wp-content/plugins/ and activating it from the database.
Step 3: Remove Malicious Code and Files
Once the scanner identifies infected files, clean them one by one — don't just delete core files blindly.
Common places hackers inject malware:
wp-config.php— check for added base64-encoded strings at the top or bottomfunctions.phpin your active theme.htaccess— look for added redirect rules/wp-content/uploads/— PHP files here are almost always malware (no PHP should exist in uploads)- Plugin files — especially nulled/pirated plugins
For core WordPress files, the safest approach is to replace them entirely. Download a fresh copy of WordPress from wordpress.org matching your current version, then overwrite wp-admin/ and wp-includes/ completely. Do not overwrite wp-content/ or wp-config.php.
// Check wp-config.php for anything like this — it's malware:
eval(base64_decode('aGVsbG8gd29ybGQ='));
// Or obfuscated code like:
$_0x4f3a = array(...); // suspicious variable names with hex
Step 4: Change All Passwords and Secret Keys
Assume every credential is compromised. Change everything.
- WordPress admin password — change from wp-admin or directly in the database
- Database password — update in cPanel and in
wp-config.php - FTP/SFTP passwords — update in hosting control panel
- Hosting account password
- WordPress secret keys — regenerate at wordpress.org/secret-key and paste into
wp-config.php(this logs out all users)
Also delete any admin users you don't recognize in Users → All Users.
Step 5: Update Everything
Most WordPress hacks happen through outdated plugins, themes, or WordPress core. Update everything immediately after cleaning.
- WordPress core → update to latest version
- All plugins → update every single one
- All themes → update, and delete unused themes
- Delete any nulled/pirated plugins or themes permanently
Step 6: Clean the Database
Hackers often inject content into your database — fake admin accounts, spam links in posts, or malicious redirects in options.
In phpMyAdmin, run these SQL queries to find injected content:
-- Check for suspicious admin accounts
SELECT * FROM wp_users;
-- Look for spam links or injected scripts in posts
SELECT ID, post_title, post_content FROM wp_posts
WHERE post_content LIKE '%eval(%'
OR post_content LIKE '%base64_decode%'
OR post_content LIKE '%
Need Help with Your WordPress Project?
Let's discuss how I can help you build something amazing!
Get in Touch →