A hacked WordPress site can feel like a nightmare—traffic drops, rankings disappear, users get malware warnings, and your brand reputation takes a major hit. But here’s the good news: you can clean a hacked WordPress site without losing your SEO, as long as you follow the right steps in the right order.
In this detailed guide, you’ll learn the exact process professional WordPress security experts use to safely detect, clean, restore, and protect hacked websites—while keeping your Google rankings intact. Whether your site is redirecting to spam, showing strange pop-ups, infected with malicious code, or flagged by Google, this guide will help you recover fast.
Let’s fix your site (and your SEO) step by step.
Why SEO Drops When Your WordPress Site Gets Hacked
When hackers inject malicious code into your WordPress environment, it creates technical issues that directly affect search engines. Some common SEO-damaging hack behaviours include:
-
Spam redirects
-
Fake pharma or casino pages
-
Malware downloads
-
Blocked access due to Safe Browsing warnings
-
Massive server resource usage slowing the site
-
Google indexing injected URLs
-
Blacklisting by hosting companies
If Google detects suspicious behaviour, it may:
-
Add a “Hacked Site” label
-
Remove pages from SERPs
-
Lower your rankings
-
Freeze your Ads campaigns
-
Prevent crawling temporarily
That’s why it’s crucial to clean your site properly without deleting important SEO files like sitemaps, robots.txt, canonical tags, or permalinks settings.
Step-By-Step Guide: How to Clean a Hacked WordPress Site Without Losing SEO
Step 1: Stay Calm and Create a Full Backup
Before touching anything, take a complete backup of your hacked site so nothing is lost during the cleanup.
Back up:
-
Files (
public_html, plugins, themes) -
Database
-
.htaccess -
robots.txt -
wp-config.php
If you can access cPanel, you can use:
If using SSH:
This backup is your safety net—and often helps diagnose where the hack entered.
Step 2: Put Your Site in Maintenance Mode (SEO-Safe)
Instead of disabling the entire site (which can hurt SEO), put it into a 503 maintenance mode, which tells search engines “we’re fixing things; don’t penalize us.”
Add this to .htaccess temporarily:
Create a maintenance.html file with:
This keeps your SEO safe while cleaning.
Step 3: Scan Your Site for Malware
Use at least two scanners to ensure accuracy:
Online Scanners
-
Sucuri SiteCheck
-
Quttera
-
VirusTotal URL Scanner
Server-Level Scanners
-
Imunify360 (most hosting)
-
cPanel Virus Scanner
Plugin Scanners
-
Wordfence
-
iThemes Security
-
PatchStack
-
MalCare (deep scan)
These tools detect malicious PHP files, injected JavaScript, suspicious iframes, spam links, and malware redirects.
Step 4: Identify the Type of Hack
Common WordPress hacks include:
1. Redirect Hacks
Your site redirects users to spam websites (pharma, adult, gambling).
2. Malware in Core Files
Modified versions of:
-
wp-config.php -
wp-settings.php -
functions.php -
index.php
3. SQL Injection
Spam posts or content appear automatically.
4. File Upload Hacks
Malicious scripts inside:
-
/wp-content/uploads/ -
/wp-includes/ -
/tmp/
5. Hidden Admin Users
Hackers create secret admin accounts.
Check:
Or in phpMyAdmin:
Remove unknown accounts immediately.
Step 5: Clean the Infected WordPress Files
1. Replace Core WordPress Files (Safest Method)
Download a fresh copy of WordPress from wordpress.org
Delete everything except:
-
/wp-content/ -
/wp-config.php
Upload fresh files to the server.
2. Clean the wp-config.php File
Look for strange code such as:
or
Remove them.
3. Clean .htaccess File
Many hacks hide here.
Safe default for WordPress:
4. Clean Theme & Plugin Files
Check functions.php for:
Check header.php and footer.php for weird scripts.
If needed, delete the theme/plugin folder and reinstall fresh copies.
Step 6: Clean the Database (SEO-Safe)
Open phpMyAdmin → Search tab.
Search for these keywords:
Remove only suspicious entries.
Fix Spam Posts and URLs
Check for:
-
posts added automatically
-
spam categories
-
malicious redirects in
wp_options
Open wp_options, check:
-
siteurl -
home -
permalink_structure -
rewrite_rules
Make sure no iframe or JS exists.
Step 7: Remove Backdoors (Critical for SEO Recovery)
Hackers leave hidden backdoors so they can re-infect you later.
Common locations:
-
/wp-content/uploads/202X/ -
/wp-includes/ -
random PHP files in root directory
Search for suspicious files via SSH:
Delete anything suspicious inside /uploads/—uploads should never contain PHP files.
Step 8: Update Everything Immediately
Update:
-
WordPress core
-
Themes
-
Plugins
-
PHP version
-
Database version (if required)
-
Hosting security tools
Make sure to delete unused themes and plugins.
Inactive plugins can still be exploited.
Step 9: Regenerate SEO Files Correctly
Rebuild .htaccess
Settings → Permalinks → Save
Rebuild robots.txt
Use:
Regenerate Sitemap
If using Yoast → SEO → Tools → Rebuild index
If using RankMath → Sitemap Settings → Regenerate
These help Google re-crawl fast.
Step 10: Submit Clean Site to Google (Remove Warnings)
Go to Google Search Console:
-
Remove malware warning
→ Security Issues → “Request Review” -
Submit sitemap
/sitemap_index.xml -
Fetch & re-crawl
→ URL Inspection → Request Indexing -
Check Manual Actions page
Once Google verifies your site is clean, rankings begin restoring within days.
Step 11: Add Strong Security to Prevent Future Hacks
After cleaning, secure your WordPress site.
Install Security Plugins
-
Wordfence
-
iThemes Security
-
PatchStack
-
Sucuri Firewall
Set File Permissions
Use SSH:
Disable PHP Execution in uploads
Create .htaccess inside uploads folder:
Block XML-RPC attacks
Add to .htaccess:
Enable 2FA for all admins
Protect admin logins with two-factor authentication.
Final Thoughts: Recover Your Rankings the Smart Way
Cleaning a hacked WordPress site is stressful, but when you follow a structured process, you can:
-
Remove all malware
-
Restore a clean site
-
Prevent future hacks
-
Recover Google rankings fast
-
Maintain your SEO health
If you take the right steps immediately, your traffic and rankings usually return within 7–15 days.
FAQs
1. Does cleaning a hacked WordPress site affect SEO?
If done correctly, no. Using 503 maintenance mode ensures Google does not penalize your site.
2. How long does it take for SEO to recover after a hack?
Typically 7–15 days, depending on how fast Google re-crawls your site.
3. Should I delete all files when a site is hacked?
No. Only delete infected files. Do not remove /wp-content/ or your SEO files.
4. Can I clean the hack without using plugins?
Yes, using file replacement, manual scanning, and SSH commands.
5. How did my WordPress site get hacked?
Common reasons include outdated plugins, weak passwords, nulled themes, and insecure hosting.
6. What if the hack returns after cleaning?
A hidden backdoor is still present. Re-scan uploads folder and replace the theme.