Injected JavaScript in the database
Script tags appended to posts, widgets, or theme options — often autoloaded on every page and pointing at a rotating chain of throwaway domains.
Guide · Redirect infections
Visitors report landing on ads, fake giveaways, adult content, or “your device is infected” pages — but when you open the site, everything looks normal. That mismatch is the signature of a WordPress redirect hack, and it is the most common way owners discover a compromise.
Published Last reviewed
Why you cannot see it
Redirect malware almost always cloaks. It commonly fires only for visitors arriving from Google or social links, only on mobile devices, only once per visitor (a cookie suppresses repeats), or never for logged-in administrators. The owner types the domain directly, sees a healthy site, and assumes the reports are mistaken.
That behavior is intentional: the longer the owner stays convinced nothing is wrong, the longer the redirect earns for whoever installed it. Treat repeated visitor reports as evidence, not noise.
Where it lives
Script tags appended to posts, widgets, or theme options — often autoloaded on every page and pointing at a rotating chain of throwaway domains.
A few obfuscated lines added to functions.php or a plugin file, executing on every request and easy to miss in a casual review.
Server-level rules that redirect specific user agents or referrers before WordPress runs at all — invisible to plugin scanners.
A plugin or mu-plugin you never installed, sometimes named to look official, reinstating the redirect whenever other copies are cleaned.
An account you did not create, used to reinstall the redirect after each cleanup attempt.
Occasionally the redirect rides in through an injected third-party embed rather than the site itself — worth ruling out before a full cleanup.
First steps
Reproduce the redirect using a private window, a mobile device, and a Google-search entry point. Capture the destination URL and the time.
Do not start deleting files. Note timestamps, keep existing backups untouched, and export the database before changing anything.
Hosting panel, WordPress administrators, and database credentials — and remove any administrator account you cannot vouch for.
Security Issues and the URL Inspection tool show what Google sees, including cloaked spam pages you cannot see in a browser.
Restoring last week’s backup often restores last week’s infection, and never closes the entry path that let it in.
Fixing it properly
A redirect hack that is “fixed” by deleting one script line usually returns, because the injection point — a vulnerable plugin, a stolen credential, a rogue admin, or persistence elsewhere in the account — was never addressed. A proper cleanup rebuilds files from trusted sources, cleans the database, verifies .htaccess and PHP configuration, reviews every account, and closes the most likely entry path before declaring the site recovered.
If Chrome already shows “Deceptive site ahead” or Google flags the site, the warning is removed by requesting review after the cleanup — not before, since a failed review lengthens the process.
Common questions
Cloaking. The malware checks the referrer, device, and cookies before firing, so casual checks by the owner show a normal site while search visitors are monetized. Reproduce it under the victim’s conditions, not your own.
Google reacts to what the site serves: spam pages get indexed, cloaking violates policy, and Safe Browsing can flag the domain. Rankings usually recover after a verified cleanup and review request, but the longer the redirect runs, the slower the recovery.
Treat that as symptom relief, not recovery. If the entry path and any remaining persistence were not addressed, the same infection commonly returns within days — often slightly better hidden.
Most commonly through a vulnerable plugin or theme, a reused or stolen password, or a neighboring compromised site on the same hosting account. Identifying the likely path is part of the cleanup, because it decides what must change to stay clean.