How SEO spam hides in WordPress, how to detect cloaked pages, where the injection lives, and the cleanup order that stops reinfection.

WordPress SEO spam is an attack that injects hidden pages, links, or redirects into your site so it ranks for someone else's keywords, usually pharmacy, casino, replica goods, or loan spam. The attacker is not trying to break your site. They are borrowing your domain's reputation to rank their own content, which is why the infection is built to stay quiet.
That quietness is the whole problem. A defacement gets noticed in an hour. SEO spam can sit on a site for months, quietly poisoning the domain, until Google flags it or a client asks why the firm's website shows up in a search for sportsbooks.
The fastest check is a site search. Open Google and search site:yourdomain.com with no space after the colon. You are looking for pages you never created, titles in another language, or product names that have nothing to do with your business. Page two onward is where it usually hides.
Then check Google Search Console. Look at Pages, then Indexed, and sort for URLs you do not recognise. Also open Security Issues. If Google has already caught it you will see a Hacked Content warning there, which tells you the clock is running.
A detail that catches people out: the spam is often cloaked. The page looks completely normal in your browser and only serves spam to Googlebot or to visitors arriving from a search result. So "I looked and the page is fine" is not evidence of anything. Use the URL Inspection tool in Search Console and choose View Crawled Page, because that shows what Google actually received.
In the sites we have cleaned, SEO spam lives in a small number of predictable places. Checking these in order finds it most of the time.
| Location | What to look for |
|---|---|
| Database, wp_posts | Published posts or pages with spam titles, often dated years ago to hide in the archive |
| Database, wp_options | Injected content in autoloaded options, and rogue values like a changed siteurl or home |
| Theme files | Appended code at the bottom of functions.php or header.php, usually base64 or hex encoded |
| mu-plugins | A directory most owners never open, so a single dropped file runs on every request with no way to deactivate it |
| Uploads folder | PHP files inside wp-content/uploads, which should never contain executable code |
| .htaccess | Rewrite rules that redirect only search traffic or only mobile visitors |
| wp-config.php | Code added above the database credentials, or an extra include of a file elsewhere |
The single most useful habit is to stop thinking of it as one file. Most real infections have a payload, a backdoor that re-adds the payload, and often a second backdoor that re-adds the first. Removing the visible spam and stopping there is why sites get reinfected within days.
Work in this order. Skipping the early steps is what turns a two hour job into a repeat job.
eval(, base64_decode(, gzinflate(, str_rot13(, assert(, preg_replace with the /e modifier, and any PHP file inside uploads. Read what you find. Not every match is malicious, which is exactly why this step cannot be automated blindly.Cleaning the site does not restore your rankings by itself, because the spam pages are still in Google's index. Those URLs are gone now, so they should return a 404 or a 410. A 410 is the stronger signal, since it tells Google the page is permanently gone rather than temporarily missing.
Then go to Search Console, open Security Issues, and request a review. Say plainly what happened, what you removed, and what you changed to prevent it. Reviews typically come back within a few days. Submit your sitemap again afterwards so Google re-crawls the pages you actually want indexed.
Expect a dip. Even after a clean review, rankings take time to recover, and how much you lose usually tracks how long the spam sat there before anyone noticed. That is the real cost of a quiet infection.
Almost every SEO spam case we have handled traces back to the same short list: an outdated plugin, a weak or reused admin password, or an abandoned plugin that no longer receives security fixes. The fixes are unglamorous and they work.
Do it yourself if the site is small, you are comfortable with SFTP and the database, and you have time to be thorough. Get help if the site earns money, if it has already been cleaned once and came back, if you cannot find the backdoor, or if Google has flagged you and every day of the warning is costing trust.
We have recovered more than 50 hacked WordPress sites, including a coordinated casino spam cleanup across 25 law firm sites at once. If you would rather hand it over, our hacked site repair is a flat price and we find the backdoor, not just the symptom.
$199 within 2 business days, or $299 the same day. Full refund if we cannot clean it.
Start a repair →Free site check, plain report, no sales call.
or email contact@backstopweb.com