WordPress hacked: spam pages, redirects and strange Google results

PlatformWordPress Doing it yourselfHalf a day to a day, and only if you are comfortable in files and the database Checked

Written and checked by Sajid, Founder & Web Engineer

The short answer

An attacker got in, usually through an out-of-date plugin, theme or a reused password, and added files that redirect visitors or publish spam pages. The content you made is still there. Cleaning it means taking a copy for evidence, finding and removing the added code, changing every password and key, closing the hole that let them in, and then asking Google to recheck. Done in that order, the site comes back clean.

Is this your problem?

  • Visitors, or only visitors arriving from Google, are redirected to a site you do not own
  • Google shows pages in Japanese, or for pills, loans or counterfeits, under your domain
  • New admin users you did not create, or posts and pages you did not write
  • Google Search Console sends a Security Issue or a social-engineering warning
  • The host suspended the account, or the site is flagged deceptive or dangerous
  • Strange files in the site root or in wp-content/uploads, often with random names

What usually causes it

1
An out-of-date plugin or theme with a known hole

How to tell: The most common way in by far. A plugin that was not updated had a public vulnerability.

2
A reused or weak admin password

How to tell: The same password leaked from another site, or was guessed by a brute-force bot.

3
A nulled, pirated plugin or theme

How to tell: Pirated premium code very often ships with a backdoor built in.

4
A shared server where another site was hacked

How to tell: On cheap shared hosting, one compromised site can reach its neighbours.

5
Old backdoors left from a previous infection

How to tell: A site cleaned before by only deleting the visible spam, which left the way back in.

Before you touch anything

  • Take a full copy of the site, files and database, before you change anything. It is your evidence and your undo, even though it contains the infection.
  • Do not simply delete the visible spam and stop. If the backdoor stays, it returns within days.
  • Put the site into maintenance mode or take it offline while you work, so visitors are not sent to the attacker.

How to fix it, step by step

  1. 1

    Confirm it and capture the evidence

    Search Google for site:yourdomain.com to see the spam pages it indexed. In Search Console open Security Issues and Removals. Save screenshots and the list of bad URLs; you will need them at the end.

  2. 2

    Change every password and secret now

    Reset all WordPress admin passwords, the hosting panel, FTP or SFTP, and the database password. In wp-config.php replace the security keys, the AUTH_KEY block, with fresh ones from the official WordPress salt generator. This logs every attacker out at once.

  3. 3

    Find the recently changed files

    In the host file manager or over SFTP, sort files by last modified. Malware is usually recent and lands in the site root, in wp-content/uploads (which should hold no PHP at all), or in mu-plugins. Code full of eval, base64_decode or long random strings is the payload.

  4. 4

    Replace core, plugins and themes from clean copies

    Delete wp-admin and wp-includes and reinstall WordPress core of the same version from wordpress.org. Reinstall each plugin and theme fresh from a trusted source. Never reinstall a nulled plugin, and delete any plugin or theme you do not use.

  5. 5

    Clean the database and remove rogue admins

    Check the users table for admin accounts you did not create and delete them. Look in the options table for injected scripts, and scan posts for hidden spam links. Keep your evidence copy in case you remove too much.

  6. 6

    Close the hole that let them in

    Update everything to current versions. Remove abandoned plugins. Set every password to a long unique one and turn on two-factor login. This step is the point of the whole job; skip it and you will be back here.

  7. 7

    Ask Google and your host to recheck

    Once it is genuinely clean, use Search Console: request a review under Security Issues, and submit the bad URLs under Removals. If the host suspended you, tell them it is cleaned so they lift it.

Stop and get help if

  • You are not comfortable editing files and the database. One wrong delete on a live shop can lose orders, and a missed backdoor brings it all back.
  • The site is a business losing money or trust every hour it redirects customers to a scam.
  • It has been cleaned before and keeps coming back, which means a backdoor was missed and needs a thorough professional sweep.
  • Customer data may have been exposed, which can carry a legal duty to report. Get advice quickly.
Fix it for me

Stop it happening again

  • Update WordPress, plugins and themes promptly, and delete anything you do not use.
  • Use a long unique password for every admin, plus two-factor login.
  • Never run nulled, pirated plugins or themes.
  • Keep a daily off-site backup you have restored at least once, so a clean copy always exists.
  • Put the site behind a firewall or a security plugin that blocks brute-force logins.

Questions people ask

Will I lose my content?

Usually not. Hacks add files and spam; they rarely delete your pages. Your clean backup and the database protect what is yours.

I deleted the spam pages but they came back. Why?

A backdoor is still in the files or database, re-creating them. Deleting the symptom is not cleaning the site. The hole has to be closed.

How do I get the deceptive-site warning removed?

Clean the site fully, then request a review in Google Search Console under Security Issues. It usually clears within a day or two once Google rechecks.

Can a cheap shared host be the cause?

Yes. If a neighbour on the same server is hacked, it can spread. After cleaning, ask the host to confirm the account itself is clean.

Not sure where your site stands?

Paste the address. Security, speed, SEO and how old the tech is, in about ten seconds.

Still broken? We can fix it.