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.
- 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?
| Location | What to look for |
|---|---|
| .htaccess | RewriteRules sending visitors to unknown domains |
| wp-config.php and index.php | Unfamiliar include lines or long encoded strings |
| Theme header.php, footer.php, functions.php | Script tags or base64, eval, gzinflate code |
| Plugins folder | Plugins you did not install, odd names |
| wp-content/uploads | PHP files (uploads should contain media, not code) |
| Database: wp_options, wp_posts | Script tags injected into siteurl, widgets or post content |
| Users | Unknown administrator accounts |
How do you clean it, step by step?
- Back up the hacked site so nothing is lost and evidence is kept.
- Put the site in maintenance mode if it is harming visitors.
- Change all passwords and remove unknown users.
- Replace core files with a fresh copy of the same WordPress version.
- Reinstall plugins and themes from official sources; delete anything nulled or unused.
- Clean .htaccess, wp-config.php and uploads; remove PHP files from uploads.
- Search the database for script tags and unfamiliar URLs.
- Update PHP, WordPress and every plugin.
- Harden: firewall, two-factor login, file editing disabled, backups.
- Check Google Search Console, Security issues, and request a review once clean.
Malware removal, blacklist cleanup, updates and a hardened setup with backups and a firewall. Free first check of your site.
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 removal, blacklist cleanup, updates and a hardened setup with backups and a firewall. Free first check of your site.
More WordPress guides
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.







