WordPress Security ServicesMalware Removal
SEO Spam

WordPress Pharma Hack: How to Find and Remove Viagra and Cialis Spam

Searching for your own site shows pages selling viagra, cialis or "online pharmacy" products, but your site looks perfectly normal. That's the pharma hack, one of the oldest and most stubborn SEO spam infections on WordPress. Here's how it works, where it hides, and how to remove it and get Google to forget it.

Sergey By Sergey, WordPress security specialist Updated 2 min read
In this guide
  1. How the pharma hack works
  2. How to confirm it
  3. Where the pharma hack hides
  4. How to remove it
  5. How to clean up Google

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

  1. Search site:yourdomain.com viagra and site:yourdomain.com cialis.
  2. In Search Console, use URL Inspection → Test live URL on an affected page and look at the rendered HTML Google sees.
  3. Check Security issues in Search Console for “hacked content”.
  4. 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

  1. Back up the site as it is.
  2. Reinstall core, plugins and themes from clean copies (see my step-by-step guide).
  3. Search the database for pharmacy keywords and encoded options, and remove injected content carefully without breaking serialized data.
  4. Check .htaccess and mu-plugins for conditional rules and loaders.
  5. Find the backdoor and the entry point: the pharma hack is persistent, so anything missed brings it back.
  6. 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.

Sergey, WordPress Security Specialist
About the author
Sergey, WordPress Security Specialist

10 years in WordPress security and incident investigation, and more than 200 websites cleaned of malware. Top Rated on Upwork with a 100% Job Success score. More about me

Frequently Asked Questions

Why can't I see the pharma spam on my site?

Because it uses cloaking: it only shows the spam to search engine crawlers, or to visitors arriving from a search. Normal visitors and logged-in admins see the real site. Google's URL Inspection tool shows what Google actually sees.

My scanner says the site is clean. Can it still have the pharma hack?

Yes, and it's common. Pharma hack code is often stored in the database or hidden in legitimate-looking files, and only activates for search engines, so scanners that browse the site like a normal visitor miss it.

How long until the spam disappears from Google?

After a complete cleanup, the spam URLs drop out over several weeks as Google recrawls them. Making them return 404 or 410 and using the Removals tool for the worst ones speeds it up.

Need a hand?

Let me clean your WordPress site for you

Send me your site URL and what you're seeing. I'll reply with what I think is going on and the next step.

$95 per infected site · 1-month guarantee · direct contact with the specialist

Get My Site Cleaned →