Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared Managed Cloud India
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Best lists Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Troubleshooting · Troubleshooting

How to Fix a Site Redirecting to Spam in WordPress

Short answer

A WordPress site that redirects visitors to spam has usually been hacked, so treat it as a security incident, not a settings error. First, save a copy of the infected site, change every password, and replace the security keys in wp-config.php. Then scan the site, remove the injected code from files and the database, update everything, and ask Google to review the site in Search Console.

Key takeaways

  • A redirect to an unrelated spam, gambling, or pharmacy site is a sign of a hack, not a normal WordPress redirect.
  • Many redirect hacks fire only for mobile visitors or people who arrive from Google, so the owner may see a normal site.
  • Save a copy of the infected site before cleaning, because it holds clues about how the attacker got in.
  • Changing security keys in wp-config.php logs every user out, including an attacker using a stolen session.
  • A remote scan alone cannot prove a site is clean, because it cannot see files on the server.
  • Google reviews a hacked site only after every listed issue is fixed on every page, and a review can take several days or weeks.

What does it mean when your WordPress site redirects to spam?

It means injected code is sending some visitors to a spam site instead of your pages.

Google defines hacked content as content placed on a site without permission because of a security weakness, and it lists redirects as one form of that content in its spam policies guidance. The destination is often a pharmacy, gambling, adult, or fake prize site that has no link to your business.

A normal WordPress redirect stays inside your own site, for example from HTTP to HTTPS or from an old page to a new one. A redirect to an unrelated spam domain is different, and it needs a security fix, not a redirect plugin setting.

Why does the redirect show only sometimes?

It shows only sometimes because the injected code checks who the visitor is before it fires.

Wordfence calls this trick spamvertizing: a hacked site sends traffic to a malicious site, as described in its WordPress security guide. The code may fire only for Google visitors, only on mobile phones, or only for logged-out people.

That is why you can load your own homepage and see nothing wrong while a customer reports a spam page. Test the site in a private window, on a phone using mobile data, and by clicking a result in Google search.

How do you confirm the redirect is a hack and not a setting?

Check what Google sees, what a remote scanner sees, and what your own site settings say.

First, search Google for site:yourdomain.com with your real domain. Google advises this check in its malware prevention guide, because unknown pages or topics you did not write can show that the site was hacked.

Next, run your address through Sucuri SiteCheck, a free remote scanner that checks for known malware, blocklist status, website errors, and out-of-date software. Sucuri states that the scanner only sees what is visible at browser level, so it will not detect anything on the server side.

Then open Settings → General in WordPress and check the WordPress Address and Site Address fields. If those two fields point to your own domain, a wrong setting is not the cause.

If they point to a spam domain, change them back only after you have saved a copy of the site. The change alone will not remove the code that set them. For a wider check, read how to tell if your WordPress site is hacked.

CheckWhat it showsWhat a bad result means
site: search in GooglePages Google has indexed for your domainSpam pages you did not create
Sucuri SiteCheckMalware and blocklist status seen from outsideKnown malware or a blocklist listing
Search Console Security issuesProblems Google found on your siteHacked content, malware, or phishing
Settings → GeneralWordPress Address and Site AddressA spam domain in either field
Users → All UsersAdmin accounts on the siteAn admin you did not create

What should you do first before you clean anything?

Save a copy of the infected site, tell your host, and write down what you saw.

WordPress guidance for a hacked site starts with staying calm and writing down the symptoms, the time you noticed them, and what changed recently, such as a new plugin or theme change. That note becomes the record your host or a cleanup service will ask for.

Take a full backup of the files and database even though the site is infected. Do not delete files yet, because the infected copy holds clues about the entry point. Ask your host to keep a copy too, and to check whether the account was suspended or flagged.

If the site is sending visitors to a scam or phishing page right now, put it in maintenance mode or take it offline until the redirect is gone. A short outage is safer than sending more visitors to a harmful page.

Where does redirect code usually hide?

It usually hides in .htaccess, theme files, plugins, wp-config.php, or the database.

The .htaccess file in the site root is a common target, because a few rewrite rules there can redirect every visitor before WordPress loads. Look for RewriteRule lines that point to a domain you do not own, or for long encoded strings you did not add.

Theme files are the next place to look, mainly functions.php, header.php, and footer.php in the active theme. Plugin files, must-use plugins in wp-content/mu-plugins/, and the wp-content/uploads/ folder can also hold injected PHP files.

The database can hold the redirect too, in wp_options values such as siteurl and home, in post content, or in widget text. A file scan alone will not find a database injection, so check both places. The guide to cleaning a hacked WordPress site covers the full file and database check in order.

How do you remove the redirect step by step?

Work in order: lock the site down, scan it, replace bad files, then check the database.

1. Change every password and replace the security keys

Change the WordPress admin password, the hosting account password, the SFTP password, and the database password, for every user with access, not just your own account. Then replace the eight security keys and salts in wp-config.php with a fresh set from the WordPress secret key generator.

The wp-config.php handbook states that you can change these keys at any point to invalidate all existing cookies, which means every user has to log in again. That step ends a session an attacker may already hold, which a password change alone does not always do.

2. Scan the site from inside and outside

Install Wordfence from Plugins → Add New and run a full scan from Wordfence → Scan. Wordfence compares core, plugin, and theme files with the official copies and flags files that were changed, added, or matched to known malware.

Run Sucuri SiteCheck again as the outside check. A clean remote result is useful, but it does not prove the server files are clean, because a remote scanner cannot read them.

3. Replace core files and check .htaccess

Download a fresh copy of the same WordPress version you run from WordPress.org, then replace the wp-admin and wp-includes folders and the root files, except wp-config.php and .htaccess. Do not use a different version, because mismatched files can break the site.

Open .htaccess and compare it with the standard WordPress block between # BEGIN WordPress and # END WordPress. Remove rewrite rules outside that block that point to another domain. Google also advises keeping a backup copy of .htaccess before you change it, in its malware prevention guide.

4. Check plugins, themes, and the database

Delete any plugin or theme you do not recognise, and reinstall the rest from WordPress.org or the vendor's own site. Remove nulled or pirated plugins and themes, because they are a known entry point and a clean scan will not stop a new infection from the same source.

Check Users → All Users for admin accounts you did not create, and delete them. Search the database for script tags and unknown links, and remove injected code. If spam pages also show in search, the malware removal guide explains how to clear them.

5. Update everything and rescan

Update WordPress, every plugin, and every theme to the latest version, as of November 2026. Wordfence reported a redirect campaign that used plugin flaws that had already been patched, including an options update flaw in Simple 301 Redirects Addon Bulk Uploader version 1.2.5 and earlier, in its redirect campaign report.

Run the full Wordfence scan again after the updates. If the scan still flags files, do not ignore them. Repeat the file replacement for the flagged items, or restore a backup made before the hack started.

How do you lock the attacker out after cleaning?

Close the entry point, change the passwords again, and turn on two-factor login.

Find how the attacker got in before you call the job done. Common entry points are an out-of-date plugin, a weak admin password, a stolen hosting password, or a nulled theme. Remove or update the weak item, and do not restore a backup without closing that hole first.

Change every password a second time after the site is clean. WordPress hacked-site guidance gives this order for a reason: a password changed before cleaning can be stolen again by code that is still on the site.

Turn on two-factor login for every admin account, and limit admin accounts to people who need them. Remove old admin accounts, and check that no new scheduled task or must-use plugin appeared after the cleanup.

How do you check the fix worked?

Test the site the way a visitor sees it, rescan it, and check Google's report.

Load the homepage and several inner pages in a private window, on a phone using mobile data, and from a Google search result. None of them should send you to another site. Repeat the test over the next few days, because some backdoors restore the redirect after a delay.

Run a full Wordfence scan and a Sucuri SiteCheck scan, and confirm both come back clean. Search Google again for site:yourdomain.com and confirm no new spam pages appear.

Open Google Search Console, go to Security & Manual Actions → Security issues, and read the report. Google states in its Security issues help that you should select Request Review once all listed issues are fixed on all pages. Google also states that most reviews can take several days or weeks.

When should you contact your host instead of fixing it yourself?

Contact your host at once if you cannot log in, if the redirect returns, or if the host disabled the site.

Your host can check server logs, restore a backup from before the hack, and scan files you cannot reach from WordPress. Ask the host for the date the files first changed, and for a backup from before that date.

Contact a cleanup service if the scan keeps finding new files, if the redirect returns within a day, or if spam pages keep appearing in Google after you cleaned the site. Those signs point to a backdoor you have not found yet, and each failed cleanup gives the attacker more time.

If the site takes payments or stores customer data, tell your host and check whether any customer data was reached. Do not wait for a clean scan before you report a possible data problem to the host.

What mistakes should you avoid?

Do not delete files before you back them up, and do not ask Google for a review before the site is clean.

  • Deleting the first suspicious line you find, while a backdoor elsewhere restores it within hours.
  • Changing only the WordPress password, while the hosting, SFTP, and database passwords stay the same.
  • Restoring a backup made after the hack started, which brings the same code back.
  • Trusting a clean remote scan as proof that the server files are clean.
  • Requesting a Google review before every listed issue is fixed, which can slow the next review.
  • Leaving an out-of-date plugin in place after cleaning, which leaves the same entry point open.

Spam page hacks often appear with redirect hacks, so check for both. The pharma hack guide covers one common spam page type.

The Japanese keyword hack guide covers another spam page type that often appears after a hack.

The backup guide shows how to keep a clean copy ready before the next incident.

Frequently asked questions

Why does my WordPress site redirect to spam only on mobile?

The injected code often checks the visitor device before it fires, so it sends mobile visitors to a spam site while desktop visitors see the normal site. Test the site on a phone using mobile data in a private window. A mobile-only redirect still means the site was hacked, and you should follow the same cleanup steps as for any redirect.

Why does my site look fine to me but redirect my visitors?

Many redirect hacks exclude logged-in admins, so the owner sees a normal site while logged-out visitors are sent elsewhere. The code may also fire only for people who arrive from Google search. Log out, use a private window, and test from a phone and from a search result to see what visitors see.

Can I fix a spam redirect by changing the site URL in Settings?

No, changing the WordPress Address or Site Address will not remove injected code from files or the database. If those fields point to a spam domain, change them back after you save a copy of the site, then scan the files, check .htaccess, and check the database. The redirect will return if the code that changed the setting is still there.

How long does it take Google to remove a hacked site warning?

Google states that most reconsideration reviews can take several days or weeks. First fix every issue listed in the Security issues report in Search Console on every page, then select Request Review and describe what you fixed. Do not send a second request while one is pending, and do not request a review before the site is clean.

Should I restore a backup to fix a spam redirect?

Restoring a backup made before the hack started is often the fastest fix, but only if you also close the entry point first. A backup made after the hack started may contain the same malicious code. After a restore, update everything, change every password again, replace the security keys, and rescan the site before you ask Google for a review.

What if the redirect comes back after I clean the site?

A returning redirect means a backdoor is still on the site, often in a must-use plugin, a drop-in file, the database, or a scheduled task you did not create. Rescan the files, check .htaccess again, look for unknown admin users, and check for files changed after your cleanup. If it returns a second time, ask your host or a cleanup service for help.

Sources

  1. How to Protect Yourself from WordPress Security Issues and Threats Wordfence
  2. Malicious WordPress Redirect Campaign Attacking Several Plugins Wordfence
  3. Sucuri SiteCheck: Free Website Malware and Security Checker Sucuri
  4. How to Prevent Malware Infection Google Search Central
  5. Security Issues Report Google Search Console Help
  6. wp-config.php WordPress Developer Resources
  7. Fix WordPress Hacked Redirect: Stop Redirects to Spam Sites MalCare

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

WPLegible editors

Researched from the primary sources listed above and checked against our editorial rules. About the site · How we test