In this guide
How the pharma hack works
Attackers want your site’s reputation in Google to rank their pharmacy pages. The pharma hack:
- injects spam (pharmacy links, keywords and pages) into your site;
- cloaks it, serving spam only to search engines and keeping it hidden from you;
- sometimes redirects visitors who come from Google to an online pharmacy;
- often rewrites page titles and descriptions in search results.
The same technique is used for casino, payday loan and Japanese keyword spam. My SEO spam removal page covers those too.
How to confirm it
- Search
site:yourdomain.com viagraandsite:yourdomain.com cialis. - In Search Console, use URL Inspection → Test live URL on an affected page and look at the rendered HTML Google sees.
- Check Security issues in Search Console for “hacked content”.
- Look at Pages in Search Console for a sudden jump in indexed URLs.
Where the pharma hack hides
| Place | What to look for |
|---|---|
| Theme files | Code in functions.php, header.php or footer.php that checks for search engine user agents or referrers |
| The database | Spam stored in wp_options (often encoded), hidden posts, or modified post content |
| Fake plugins and must-use plugins | Plugins that don’t appear in your list but load on every request |
| WordPress core files | Code added to wp-blog-header.php, wp-load.php or similar |
.htaccess |
Rules that send search engine traffic to a spam generator file |
| Uploads and random folders | Spam generator scripts and cached spam pages |
How to remove it
- Back up the site as it is.
- Reinstall core, plugins and themes from clean copies (see my step-by-step guide).
- Search the database for pharmacy keywords and encoded options, and remove injected content carefully without breaking serialized data.
- Check
.htaccessand mu-plugins for conditional rules and loaders. - Find the backdoor and the entry point: the pharma hack is persistent, so anything missed brings it back.
- Change all passwords and end all sessions.
How to clean up Google
- Make sure spam URLs now return 404 or 410.
- Remove unknown owners in Search Console (Settings → Users and permissions) and delete any spam sitemaps they submitted.
- Submit your clean sitemap.
- Use the Removals tool for the most damaging URLs.
- If Google shows a “hacked” warning, request a review. See removing “This site may be hacked”.
From my cleanup work: the pharma hack is the infection where “but the site looks fine” is most true. In one typical case, the owner only found out because a customer searched for the business and saw “buy cialis online” as the page title. The code was a few lines in the theme’s functions.php plus a large encoded option in the database. Neither showed anything to a normal visitor, and both had to go for the spam to stop.
If you’d rather have it removed for you, the pharma hack and SEO spam removal service covers the cleanup and the Google side, for $95.