WordPress Site Redirecting to Spam? How to Find and Fix the Hack

Your WordPress site redirects visitors to spam or scam pages. Here is how to find the malicious code, clean it properly and stop it coming back.

Yrzo AI28 November 2026 3 min read

The symptoms

A redirect hack sends some or all visitors away from your WordPress site to spam, fake prize or scam pages. Common signs:

  • visitors from Google or mobile get redirected, but you (logged in) do not
  • the redirect happens only once per visitor, so it is hard to reproduce
  • Google shows "This site may be hacked" — see fixing the Google hacked warning
  • unknown admin users or plugins appear

Attackers make redirects conditional precisely so owners do not notice.

Step 1: Contain it

  1. Put the site into maintenance mode or take it offline if customers are being sent to scams.
  2. Change every password: WordPress admins, hosting, FTP/SFTP, database and email.
  3. Take a full backup of the infected site for investigation — do not overwrite your clean backups.

Step 2: Find the malicious code

Redirect code usually hides in a handful of places:

  • `.htaccess` — look for RewriteCond rules checking the referrer or user agent, followed by a redirect to an unknown domain.
  • `wp-config.php` and theme `functions.php` — look for eval(, base64_decode(, gzinflate( or long unreadable strings.
  • The database — search the wp_options table (especially siteurl and home) and wp_posts for injected <script> tags.
  • `wp-content/uploads` — PHP files should never be in uploads. Any .php file there is suspicious.
  • Must-use plugins in wp-content/mu-plugins, which load silently.

Compare core files against a fresh copy of the same WordPress version. Anything that differs in wp-admin or wp-includes has been tampered with.

Is your site exposed to this?

Run a free, non-intrusive check of what attackers can see from outside. No account needed.

Step 3: Clean and rebuild

The safest clean-up is a rebuild: fresh WordPress core, fresh copies of plugins and themes from official sources, and only your content and media brought across after inspection. Remove any plugin you do not recognise or no longer use.

Step 4: Close the way in

Redirect hacks almost always start with one of:

Turn on two-factor authentication, remove unused admins, and follow our WordPress hardening guide.

Step 5: Confirm it is gone

Check the site from a private window on mobile data, request a review in Google Search Console, and run a security scan to make sure nothing else is exposed. Our general hacked website recovery guide covers the wider steps, including when to notify the ICO.

A free Yrzo AI scan will flag exposed files and missing protections in about a minute. For a full post-incident check, reports start at £149 — see plans.

Related reading: "This Site May Be Hacked" Warning in Google: How to Remove It · Website Blacklisted? How to Check and Get Removed · Website Defaced? What to Do in the First 24 Hours

WordPress redirect hackWordPress site redirecting to spamfix hacked WordPress redirectWordPress malware removal
Share

Check your own website in 60 seconds

Free check, no account needed. Want the full picture? Full reports start at £149, with up to 110 checks with a 14-day money-back guarantee.

Keep reading