WordPress Malware Removal: What to Do When Your Site Is Hacked

Most hacked WordPress sites announce themselves in one of a few ways. Visitors get redirected to spam or scam pages, sometimes only on phones or only when they arrive from Google, so the site looks fine when you type the address yourself. Google shows "This site may be hacked" under your listing, or Chrome throws a red "Dangerous site" warning. Strange administrator accounts appear in your dashboard. Japanese or pharmacy spam pages start showing up when you search for your own domain. Or your host emails to say the account has been suspended.
Don't panic, but do act the same day. And do things in the right order: cleaning before you've changed passwords, or restoring a backup without closing the hole, is how sites end up hacked again a week later.
First hour: contain it
1. Back up the infected site before you touch anything
It sounds backwards, but take a full backup (files and database) of the site as it is now, and label it "infected". It's evidence of what was changed, and it's a fallback if a cleanup step breaks something. Just never restore it by accident.
2. Tell your host
Contact your hosting company's support. Many hosts will scan the account, point you to the infected files, or temporarily isolate the site. Ask them for access logs from the past few weeks, because those can show how the attacker got in.
3. Change every password, from a clean device
Change the passwords for every WordPress administrator, your hosting control panel, SFTP/FTP, the database user, and the email account that WordPress password resets go to. Do it from a computer you trust, in case the attacker got in through a stolen login. WordPress doesn't have two-factor login built in, so add it with a plugin (Wordfence's login security feature or the free Two-Factor plugin both work) as soon as the site is clean.
4. Stop visitors from being sent somewhere bad
If people are being redirected to scam pages, ask your host to put up a temporary holding page, or to restrict access while you work. A maintenance-mode plugin isn't ideal here, because it runs inside the same WordPress install that's been compromised.
Find out how bad it is
- Check your users. Go to Users > All Users and filter by Administrator. Delete any account you don't recognize (choose to attribute its content to your own account).
- Scan from outside and inside. Sucuri SiteCheck scans your site from the outside, so it only sees what a visitor's browser sees. A server-side scanner like Wordfence looks at the actual files. Use both; an outside scan coming back clean doesn't mean the files are clean.
- Check what Google sees. In Google Search Console, open Security & Manual Actions > Security issues. Google lists the problems it found there, often with sample URLs. You can also check Google Safe Browsing site status for your domain.
- Search for spam pages. Type `site:yourdomain.com` into Google and scroll. Pages you never wrote, often in another language, are a sign of injected spam.
Clean it up
You have two routes. Pick one, but don't skip the hardening that follows either.
Option A: restore a clean backup
If you have a backup you know is from before the hack started (check the dates against when the symptoms began), restoring it is usually the quickest fix. But a restore brings back the old weakness too. Straight after restoring, update WordPress, every plugin and every theme, and change the passwords again.
Option B: clean in place
If there's no clean backup, or you're not sure when it started:
- Replace WordPress core files. In Dashboard > Updates, click Re-install version to overwrite the core files. If you or your developer have command-line access, `wp core verify-checksums` in WP-CLI lists core files that were changed or added, and `wp plugin verify-checksums --all` does the same for plugins from WordPress.org.
- Reinstall plugins and themes from the source. Delete each plugin and theme folder and install a fresh copy from WordPress.org or the vendor. Remove anything you don't use. If any plugin or theme came from a "free premium" download site (nulled software), get rid of it; those are a common way malware gets in.
- Look for files that shouldn't be there. The `wp-content/uploads` folder holds images and documents, so a `.php` file in there is a red flag. Also open `.htaccess` and `wp-config.php` and look for code you didn't add, such as long scrambled strings or redirect rules.
- Check the database. Look for injected `