In this post
If your WordPress site is hacked, take it offline or put up a maintenance page, change every password, and restore a clean backup or clean the files before you reopen. Do it in that order, because cleaning a site while the attacker still has a way in only means doing it twice.
This guide is for business owners, so we've kept it to the steps you can follow or hand to your developer. WordPress.org keeps its own guide, Help I think I've been hacked, and it's worth reading alongside this one.
How do you know your WordPress site is hacked?
A WordPress site hacked in a loud way is easy to spot. Some signs are obvious: a defaced home page, a browser warning, or a hosting company email saying your account was suspended. Others are quieter.
- Strange pages or posts you never wrote, often selling pills, watches or loans.
- Visitors from Google landing on a different site.
- Admin users you don't recognise under Users in the dashboard.
- The site is suddenly slow, or customers say they got spam from your domain.
- A flood of visits to pages that don't exist on your site.
One of these doesn't prove a hack, since slow sites have many causes. Two or three together should make you act.
What should you do in the first hour?
Work through these in order.
- Take a copy first. Download the files and database as they are now. It looks odd to back up a hacked site, but you may need it to see how the attacker got in.
- Limit the damage. Switch on maintenance mode, or ask your host to suspend public access while you work. If you take card payments, pause checkout.
- Tell your host. Many hosts can scan the account, tell you which files changed and sometimes restore a backup.
- Change passwords. That means WordPress admins, hosting, FTP or SFTP, the database, and the email account tied to the admin user. Use a password manager and long, unique passwords.
- Log everyone out. Replace the secret keys in wp-config.php. Doing this signs out anyone with an open session, including the attacker. WordPress.org has a key generator for it.
Reused passwords elsewhere need changing too, because attackers try stolen logins on other sites. Don't skip this step.
Should you restore a backup or clean the site by hand?
Restoring is usually faster, provided the backup is from before the hack. That's the catch. If the infection arrived three weeks ago and your backups are only kept for two, you'd be restoring a hacked copy.
This is why we keep saying how often you back up a WordPress website matters. Keep backups somewhere other than the same server, and keep a few weeks of them.
If a clean backup exists, restore it, then update everything straight away. Otherwise cleaning is the way to go:
- Reinstall WordPress core from a fresh download, replacing the wp-admin and wp-includes folders.
- Delete every plugin and theme you don't use. Reinstall the ones you keep from their official sources, not from your old copies.
- Check the wp-content/uploads folder for PHP files. Images should be images, so a PHP file there is a red flag.
- Remove unknown admin users, and check scheduled tasks and the database for spam content.
Hand cleaning is fiddly. Malware often hides in several places and puts back what you delete. If the site earns you money, paying a developer to do it is cheaper than a second attack.
How did they get in, and how do you stop it happening again?
The most common routes are outdated plugins and themes, weak or reused passwords, and "nulled" (pirated) premium plugins. Find the likely cause before you reopen, or the same hole will let them back in.
Once the site is clean, put these in place:
- Update WordPress, plugins and themes regularly. Test big updates first on a WordPress staging site so you don't break the live one.
- Give each person their own account with the lowest role that does their job. Few people need Administrator.
- Turn on two-factor login for admins.
- Use a security plugin or your host's scanning for file change alerts.
- Run automatic off-site backups.
It's dull work, which is the reason most sites skip it. Our piece on website maintenance plans and what they include shows what ongoing care looks like, so you can judge what you'd want covered.
What about Google warnings and your search rankings?
If Google flagged your site, you'll usually see a notice in Search Console and a warning in search results or browsers. After cleaning, you can request a review there. Wait until you're sure the site is clean, because a failed review costs you time.
Also check your sitemap and robots.txt files for anything you didn't add. Hackers sometimes slip in spam URLs, and you want those gone before Google crawls again.
What should you do next?
Mid-incident? Follow the first-hour list above. Site fine for now? Spend ten minutes today checking that your backups exist and that you know where they are. Want a team to clean up or lock down a site, see our WordPress development service or send us a message with what you're seeing.
Common questions
Can I clean a hacked WordPress site myself?
You can if you're comfortable with files and the database, but malware often hides in several places. If the site earns money, a developer is usually the safer choice.
Will a hack hurt my Google rankings?
It can. Google may show a warning or remove affected pages. Clean the site fully, then request a review in Search Console.
Should I tell my customers?
If customer data may have been exposed, yes, and check the rules in your country. Ask your host or developer what was accessed first.