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

Is your WordPress site redirecting visitors to spam or scam pages? Where the malicious code hides, how to clean it and how to stop it coming back.

Card: WordPress site redirecting to spam, how to remove the hack

Table of Contents

If your WordPress site redirects visitors to spam, gambling or fake prize pages, it has almost certainly been hacked. Take a backup of the current state, change all passwords, scan files and the database for injected code (often in .htaccess, wp-config.php, theme files, fake plugins and the wp_options table), replace WordPress core files with clean copies, remove unknown admin users, update everything and then check Google Search Console for security issues. The redirect often only appears on mobile or for visitors from Google, which is why owners miss it.

Key takeaways
  • Malicious redirects often target only mobile users or search visitors.
  • Check .htaccess, theme files, unknown plugins and the database.
  • Change every password: WordPress, hosting, database, FTP, email.
  • Find and close the entry point or the hack returns.
  • Request a Google review once clean if the site is flagged.

Why do hacked sites redirect only sometimes?

Attackers hide redirects from the site owner. A typical script redirects only visitors arriving from Google, only on phones, only once per visitor, or never when someone is logged in. Imagine a dentist who checks her site daily on her laptop and sees nothing wrong, while patients searching on their phones keep landing on a lottery scam. Test from a phone on mobile data, in a private window, by clicking your site from a Google search result.

Where is the redirect code usually hidden?

LocationWhat to look for
.htaccessRewriteRules sending visitors to unknown domains
wp-config.php and index.phpUnfamiliar include lines or long encoded strings
Theme header.php, footer.php, functions.phpScript tags or base64, eval, gzinflate code
Plugins folderPlugins you did not install, odd names
wp-content/uploadsPHP files (uploads should contain media, not code)
Database: wp_options, wp_postsScript tags injected into siteurl, widgets or post content
UsersUnknown administrator accounts

How do you clean it, step by step?

  1. Back up the hacked site so nothing is lost and evidence is kept.
  2. Put the site in maintenance mode if it is harming visitors.
  3. Change all passwords and remove unknown users.
  4. Replace core files with a fresh copy of the same WordPress version.
  5. Reinstall plugins and themes from official sources; delete anything nulled or unused.
  6. Clean .htaccess, wp-config.php and uploads; remove PHP files from uploads.
  7. Search the database for script tags and unfamiliar URLs.
  8. Update PHP, WordPress and every plugin.
  9. Harden: firewall, two-factor login, file editing disabled, backups.
  10. Check Google Search Console, Security issues, and request a review once clean.
Malware cleanup and hardeningHacked, or worried you will be?

Malware removal, blacklist cleanup, updates and a hardened setup with backups and a firewall. Free first check of your site.

Request a security check

How did the attacker get in?

The usual entry points are an outdated plugin with a known vulnerability, a nulled theme with a backdoor, a weak or reused password, or another hacked site on the same hosting account. Cleaning without closing the entry point is why many sites are reinfected within weeks.

What about Google warnings and lost rankings?

If Google detected the hack, Search Console’s Security issues report lists it and search results may show a warning. Google says a review can take from a few days to a few weeks after you request it. Spam pages created by the hacker should return 404 or 410 and be removed. Full recovery steps are in how to recover a hacked WordPress site and how to remove the “This site may be hacked” warning.

Need it cleaned today?

I remove malware and malicious redirects, close the entry point, harden the site and handle the Google review. I take a full backup first and send you a plain-language report. Request a security check.

Frequently asked questions

Why does my WordPress site redirect to another site?

Usually because malicious code was injected into .htaccess, theme files, a fake plugin or the database. It often targets only mobile or search visitors.

Why can I not see the redirect myself?

Malicious redirects often skip logged-in users and repeat visitors. Test on a phone with mobile data in a private window, clicking from Google.

How do I remove a malicious redirect from WordPress?

Back up, change passwords, replace core files, reinstall plugins and themes from official sources, clean .htaccess and the database, then harden the site.

Will Google penalise my site for a hack?

Google may show warnings while the site is infected. After cleaning, request a review in Search Console; it can take days to weeks.

Sources

Malware cleanup and hardeningHacked, or worried you will be?

Malware removal, blacklist cleanup, updates and a hardened setup with backups and a firewall. Free first check of your site.

Request a security check
Written by Tanvir H

WordPress and Elementor web designer at Tanvir WebXprt, Bangladesh, with 7+ years of experience and 650+ projects for clients worldwide. Tanvir builds, fixes and speeds up WordPress sites every week and writes these guides from that hands-on work.

Keep learning

More WordPress guides

Done for you

Rather have an expert run your WordPress site?

Tanvir H is a Bangladesh-based WordPress and Elementor web designer with 7+ years of experience, 650+ projects and a 4.9 client rating. New websites, redesigns, fixes, speed, security and SEO, handled by one expert who explains everything in plain English and works with clients worldwide.

Website developmentWordPress, Elementor & WooCommerce sitesfrom $899
Fixes & speedErrors, hacks, Core Web Vitals, upgradesFree quote
SEO & paid adsRank on Google, run Meta & Google Adsfrom $300
Creative designWeb, graphic & brand identityfrom $220

Contents

Was this helpful? Spread the word and share with your network!
Facebook
Pinterest
LinkedIn
Reddit
VK
X
Telegram
Threads
Tumblr
Email
WhatsApp
Pocket

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Article