More fixes

WordPress site redirects visitors to a spam site

A customer tells you your website sent them to a "you have won a prize" page, a casino or a pharmacy. You open the site yourself and it looks fine. Or Google now shows "This site may be hacked" under your listing, your results carry Japanese or pill-shop titles you never wrote, or Chrome shows a red "Dangerous site" screen. All of these are the same thing: someone has added code to the site, and it is written to hide from the owner. Below is a rebuilt example (not a real client), then how to confirm it, how to clean it so it stays clean, and how to get Google's warning taken off.

A phone visitor who came from Google

What the checks found


  

Why you do not see it yourself

The added code is selective on purpose, so the owner is the last to notice. It typically redirects only visitors who are not logged in, only phones, only people arriving from a Google search, or only someone's first visit (it sets a cookie and leaves them alone afterwards). Some versions show Google's crawler a different page from the one people see, which is how spam titles end up in your search results while the site looks normal in your browser. The way in is usually an out-of-date plugin or theme with a known hole, a "nulled" (pirated) copy of a paid plugin, or a reused or leaked password.

First, confirm it (about 15 minutes)

  1. Visit like a stranger. On your phone, in a private window, not logged in, search Google for your business name and tap your own result. Try again on mobile data rather than your office Wi-Fi.
  2. Search site:yourdomain.com in Google. Pages you never made (Japanese text, "cheap", "casino", brand-name handbags) mean spam pages were added or are being shown to Google.
  3. Open Google Search Console, Security & Manual Actions, Security issues. Google lists what it found and sample URLs. If you have no Search Console account, the free Google Safe Browsing site status page (Google Transparency Report) shows whether the domain is flagged.
  4. Run a free outside scan such as Sucuri SiteCheck. It fetches the site the way a visitor does and often names the injected script. A clean result does not prove the site is clean; a dirty one confirms it.
  5. Look at Users in the dashboard, filtered to Administrator. An admin you do not recognise, often with a plausible name, is a strong sign.

The clean-up

  1. Take a full backup of the site as it is now (files and database) and keep it apart from your good backups. It is your evidence and your way back if a step goes wrong. Do not restore it later.
  2. Change every password that touches the site: hosting control panel, SFTP/FTP, the database user (then put the new one in wp-config.php), and every WordPress administrator. Delete admin users you do not recognise.
  3. Replace WordPress itself with a fresh copy. Dashboard, Updates, Re-install version, or upload fresh wp-admin and wp-includes folders from wordpress.org. Your content lives in the database and wp-content, so this does not touch it.
  4. Replace every plugin and theme with a fresh copy from wordpress.org or the seller's own account. Delete anything unused, anything you do not recognise, and any nulled plugin: those often ship with the backdoor already inside.
  5. Clean what a reinstall does not replace. Read .htaccess, wp-config.php and the root index.php for added lines (long unreadable strings, eval, base64_decode, rules that check for Google as the referrer). Delete any .php file inside wp-content/uploads: that folder should only hold images and documents. Check wp-content/mu-plugins, which loads silently and does not appear in the plugin list.
  6. Clean the database. Search posts and pages for <script and links you did not add, and check Settings, General that both site addresses are still yours.
  7. Log everyone out everywhere by putting fresh security keys in wp-config.php (WordPress publishes a generator at api.wordpress.org/secret-key/1.1/salt/), then update everything to its latest version and turn on two-factor login for admins.
  8. Test as a stranger again: private window, phone, from a Google result, three or four times. Re-run the outside scan. Then, and only then, ask Google for a review.

Getting Google's warning removed

What you see, what it means, what it needs

What you seeUsual causeUsual fix
Customers land on a prize, casino or pharmacy page; you never doConditional redirect for logged-out, phone or Google visitorsFull clean-up above; test as a stranger
Japanese or shop titles in your Google resultsSpam pages added, or a different page shown to Google onlyRemove them, let them 404, Removals tool, sitemap
"This site may be hacked" under your listingGoogle found injected content or spam pagesClean, then Search Console Request review
Red "Dangerous site" screen in ChromeSafe Browsing flagged malware or a scam redirectClean, then review in Search Console Security issues
Fixed it, it came back a few days laterA backdoor or an unknown admin was left, or the hole was not closedFresh copies of everything, delete stray PHP, new passwords and keys
An admin user you never createdAccount added during the break-inDelete it, change every password, fresh keys
Host suspended the account for malwareHost's own scanner found the same codeClean, then ask the host to rescan and lift it

What not to do

A clean-up like this is usually a few hours of careful work, most of it reinstalling and checking. If you would rather hand it over, that is what the box below is for. Related: a site stuck in a redirect loop, a login page that just reloads and a blank white page.