Why you can’t see it
Redirect malware is built to hide from the site owner. Most versions only redirect some visitors:
- Visitors from Google, not people who type your address.
- Phones, not computers.
- First visits only. A cookie stops it from redirecting the same person twice.
- Never logged-in users. Anyone who has logged in to WordPress is skipped.
So “it works for me” proves nothing. If customers report it, believe them.
See what visitors see
- On a phone using mobile data (not your Wi-Fi), open a private tab.
- Search Google for your business name and tap your result.
- Note the address you end up on. Screenshot it: it helps you search for the code later.
With SSH or a terminal, this shows whether the server itself redirects visitors from Google on a phone. Look for a location: line pointing to another domain:
curl -sI -e "https://www.google.com/" \
-A "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148" \
https://yourdomain.com/
If this shows no redirect but the phone test does, the redirect happens in JavaScript in the page, not on the server.
Where redirect code hides
- The database: a
<script>tag injected into posts, widgets or page-builder content, or your site address changed in Settings. .htaccess: rewrite rules that send visitors from Google or on phones to another site.- Theme files: code added to
header.php,footer.phporfunctions.php. - Fake or must-use plugins: a plugin you never installed, often hidden from the Plugins list, that adds the script to every page.
- JavaScript files: a few lines appended to the end of a real plugin’s or theme’s
.jsfile.
Check each place
1. Run a full scan
The free Moatline Malware Scanner checks posts, widgets and page-builder content in the database, compares every plugin with its official copy, finds fake and must-use plugins, and loads your live home page the way a logged-out visitor does to catch scripts added while the page is built. It does not imitate a visitor arriving from Google on a phone, and it does not read .htaccess rules, so also do steps 2 and 3.
2. Check your site address and posts
In Settings → General, both addresses must be your own domain. With SSH:
wp option get siteurl
wp option get home
wp db query "SELECT ID, post_title FROM wp_posts WHERE post_content LIKE '%<script%' AND post_status='publish'"
Change wp_ if your table prefix is different. Some posts legitimately contain scripts (embeds, forms), so look at what each one loads.
3. Check every .htaccess file
find . -name ".htaccess" -type f
Open each one. Lines mentioning HTTP_REFERER with google, bing or yahoo, or HTTP_USER_AGENT with android or iphone, followed by a rule sending visitors to another domain, are malicious. A normal WordPress .htaccess has only the short # BEGIN WordPress block plus rules from plugins you know.
4. Check core files
wp core verify-checksums
wp plugin verify-checksums --all
These compare your files with the official copies. Premium plugins and themes can’t be checked this way, so reinstall them from a fresh download.
After you remove it
- Clear every cache: your caching plugin, your host’s cache and any CDN such as Cloudflare. Otherwise visitors keep getting the old, infected pages.
- Change all passwords and generate new security keys in
wp-config.php. - Find the way in. Update every plugin and theme, remove ones you don’t use, and check for admin users you don’t recognise.
- Repeat the phone test the next day. If Google labelled your site, follow removing “This site may be hacked”.
Frequently asked questions
Why does my site redirect only on mobile?
Why does it only happen when I click from Google?
Can a WordPress plugin cause a redirect without being hacked?
I removed the code but the redirect is back. Why?
Scan your site for free
Moatline checks files, the database and page-builder content. Nothing changes unless you click a button.
More guides
- “This site may be hacked” in Google: how to get the warning removed
- Host suspended your WordPress site for malware? What to do next
- Unknown admin user in WordPress? How to check it, remove it and lock the door
- Japanese or pharma spam in Google results? How to fix the WordPress hack
- A website asked you to press Windows + R to “verify you are human”? Here’s what to do
- WordPress fake CAPTCHA malware (ClickFix): how to find and remove it