Solution:
Root Cause: Mobile User-Agent Cloaking and Device-Targeted Malware
Malware scripts often inspect the incoming
HTTP_USER_AGENT string to detect mobile operating systems (iOS, Android). If a mobile device is detected, the script injects an iframe or meta-refresh tag redirecting the user to adult websites, survey scams, or fake app installs, while desktop visitors see a normal website to evade detection by site owners.
Diagnostic Verification:
Browsing the site on a desktop works fine, but viewing it on a smartphone triggers immediate unwanted tab redirects.Step-by-Step Fix:
1Search for Mobile Detection Code:
Use a security scanner (Wordfence) to search theme and plugin files for wp_is_mobile(), Android, iPhone, or base64 mobile redirect strings.2Clean Theme Footer/Header:
Remove injected JavaScript snippets from footer.php or header templates that check screen width or user agent.3Clear Cloudflare / Server Page Caching:
Purge all server and CDN caches so cached mobile redirect pages are cleared.Prevention & Long-Term Monitoring:
Test your live website periodically using mobile user-agent switchers in desktop browsers.