How to Recover a Hacked WordPress Site Without Losing Your Content or SEO Rankings
A hacked WordPress site doesn’t have to mean starting over. Here’s the exact recovery process I use to clean infections, preserve content, and protect the SEO equity you’ve spent years building.
Table of Contents
Don’t Panic and Don’t Nuke the Site

The first instinct most people have when they discover their WordPress site has been compromised is to tear it all down and start fresh. I understand the impulse — it feels like the only way to be sure the infection is gone. But in my experience, that approach is almost always overkill, and it’s where companies lose the most value.
A full rebuild means you lose URL structures, internal linking patterns, metadata, redirects, and years of accumulated domain authority. Google doesn’t just hand that back to you. Even if you recreate every page perfectly, you’ll likely see a significant drop in organic traffic that can take months to recover from.
The better approach is surgical. Identify what’s infected, isolate it, clean it, and harden everything around it. I’ve recovered dozens of hacked WordPress sites this way — some with thousands of pages of content — without losing a single ranking. The key is having a methodical process and resisting the urge to make sweeping, destructive changes under pressure.
Assess the Damage Before You Touch Anything
Before cleaning a single file, I need to understand the scope and nature of the hack. Not all compromises are equal. A pharma spam injection in your header is a very different beast from a backdoor shell buried in your uploads directory. The recovery strategy depends entirely on what happened.
My first step is always to take a complete backup of the site in its current compromised state. Yes, you’re backing up a hacked site. This is critical because it gives you a forensic snapshot to reference later and a safety net if something goes wrong during cleanup. I use direct server access for this — not a plugin, because at this point you can’t trust any plugin on the site.
Next, I check Google Search Console for security issues and manual actions, review server access logs for suspicious activity, and scan the database for injected content. Tools like Wordfence’s CLI scanner and WP-CLI are invaluable here. I also cross-reference file modification dates against known clean versions of WordPress core, themes, and plugins. This tells me exactly which files were altered and when the compromise likely began.
Clean the Infection Without Destroying Content
Here’s where precision matters. My cleaning process follows a specific order designed to preserve content while eliminating every trace of the infection:
- Replace WordPress core files entirely. I download a fresh copy of the exact WordPress version the site is running and replace every core file. The
wp-contentdirectory is left untouched — that’s where your content lives. - Replace plugins and themes with clean copies. Every plugin and theme gets replaced with a fresh download from its official source, matching the installed version. Custom themes get a line-by-line audit instead.
- Audit the uploads directory. Attackers love hiding PHP backdoors in
wp-content/uploads. I search for any file that isn’t a legitimate media asset and remove it. - Clean the database. Injected scripts often live in post content, widget areas, or options tables. I use targeted SQL queries to find and remove malicious code without altering legitimate content.
The database step is where SEO preservation really happens. Your posts, pages, metadata, Yoast settings, and internal links all live in the database. By cleaning surgically rather than restoring an old backup, you keep every piece of content exactly as it was — minus the malware.
Protect Your SEO Equity During the Recovery Process
SEO damage from a hack doesn’t just come from the hack itself — it often comes from a clumsy recovery. I’ve seen companies lose more rankings from their cleanup process than from the original compromise. Here’s how I prevent that.
Never take the site offline for more than a few hours. If Google crawls your site and gets a 503 or a maintenance page for days, that’s a ranking signal you don’t want to send. I do all cleanup work on the live server or a staging clone that I can swap in quickly. If I must take the site down, I use a 503 status code with a Retry-After header — this tells Google the outage is temporary.
Once the site is clean, I immediately submit it for review in Google Search Console if there’s a manual action. I also resubmit the sitemap, request indexing on critical pages, and monitor crawl stats closely for the next two weeks. If the hack created thousands of spammy URLs, I make sure those return proper 404 or 410 status codes so Google can de-index them without affecting legitimate pages. Every redirect, every canonical tag, every robots directive stays exactly as it was before the compromise.
Harden the Site So This Never Happens Again
Cleaning a hacked site without hardening it is like mopping the floor while the faucet’s still running. In my experience, the majority of WordPress hacks exploit one of three vectors: outdated plugins, weak admin credentials, or compromised hosting environments. The fix has to address all three.
My post-recovery hardening checklist includes: forcing password resets for every user account, implementing two-factor authentication for all admin and editor roles, removing unused themes and plugins entirely (not just deactivating), setting up automated core and plugin updates for security patches, configuring proper file permissions, and adding security headers like Content-Security-Policy and X-Frame-Options at the server level.
I also set up a monitoring system that alerts within minutes if any core file changes unexpectedly. Proactive monitoring is what separates companies that get hacked once from companies that get hacked repeatedly. For our managed clients at Valley Developers, this kind of monitoring is standard — and it’s caught reinfection attempts before they could do any damage.
When to Stop DIYing and Call a Professional
I’ll be honest: basic malware cleanup is something a competent developer can handle with the right tools and process. But there are situations where DIY recovery becomes genuinely risky. If your site has been blacklisted by Google, if you’re seeing server-level rootkits, if the compromise has persisted across multiple cleanup attempts, or if you’re running a high-traffic site where every hour of downtime costs real revenue — that’s when you need someone who does this regularly.
The cost of a professional recovery is almost always less than the cost of lost SEO rankings, lost customer trust, or a botched cleanup that makes things worse. I’ve been called in to fix recovery attempts where someone accidentally deleted their entire wp_postmeta table trying to remove injected code. That’s a much harder problem to solve than the original hack.
My advice: if your WordPress site is a genuine business asset — if it generates leads, supports your brand, and ranks for competitive keywords — treat its security with the same seriousness you’d treat a production application. Have a recovery plan before you need one, and know who you’re going to call when something goes wrong.
This post represents my own professional opinion based on my experience. It is not legal, financial, or technical advice for your specific situation, and it is not a statement of fact about any third-party product, plugin, or company.