What to do if your WordPress site is hacked
Last updated
Finding out a site has been hacked is stressful, but most hacks can be cleaned up fully if you work through them in order. The common signs are a Malware Detected alert, visitors being redirected to spam or scam sites, strange new pages or administrator accounts, a warning from Google or your host, or a sudden slowdown.
This guide is a step-by-step plan using the tools in MaintainHQ. Follow it in order. The most common mistake is rushing to restore a backup before you know how the attacker got in, which simply lets them back in.
Step 1: Keep the evidence
Before changing anything, take a fresh backup. It records the site exactly as the attacker left it, which helps you find what changed and when.
- Open Backups in the left-hand menu and press Backup Now.
- Choose the site and Full site, then press Start Backup.
- When it shows Completed in History, pin it so it is not cleared away.
Do not restore over the site yet, and do not delete files at random.
Step 2: Lock the attacker out of accounts
Change passwords early, so the attacker cannot simply log back in while you work:
- Every WordPress administrator password.
- Your hosting control panel, SFTP and database passwords (from your host).
- Your own MaintainHQ password, and turn on two-factor authentication under Profile if it is not on.
If an administrator is locked out because the attacker changed their password, use Emergency reset on the site’s Security tab to sign them out everywhere and give them a single-use sign-in link. See hardening, firewall and two-factor sign-in.
Turn on the firewall for the site now if it is off.
Step 3: Find what has been changed
- Open Security in the left-hand menu, choose the Malware scan tab and pick the site.
- Press Scan now and wait for it to finish.
- Open Details on each Critical or High finding. Note the file or location, the matched code and the First seen date.
- On the site’s Security tab, check the Known vulnerabilities card. An out-of-date plugin with a known hole is the most likely way in.
- Look at the site’s Activity log in MaintainHQ, and at the Users screen in WordPress, for logins and administrator accounts nobody recognises.
The earliest First seen date tells you roughly when the hack happened. That matters when choosing a clean backup.
Step 4: Clean the site or restore a clean backup
You have two ways to remove the damage. Choose based on how much has changed since the hack began.
| Clean in place | Restore a clean backup | |
|---|---|---|
| Best when | The hack is recent, or the site has taken orders or content since | You have a backup from before the First seen date and little has changed since |
| How | Replace affected plugins and themes from trusted sources; remove unknown files and admin accounts | Restore the whole site, or just the affected files and folders, from a backup taken before the hack |
| Risk | Missing a hidden file | Losing content added since the backup (the safety backup keeps a copy) |
Cleaning in place
- Check each finding against a clean copy: the original plugin or theme, WordPress.org, or an older backup. Some findings are suspicious rather than proof.
- Replace affected plugins and themes with fresh copies from trusted sources, instead of editing out lines.
- Remove files and administrator accounts nobody recognises.
Restoring
Choose a backup taken before the earliest First seen date. To keep recent orders and content, restore only the affected files and folders (Browse files and tables in History) rather than the whole site. See restoring a backup.
Step 5: Close the way in
If you skip this step, the site is likely to be hacked again, often within days.
- Install every security update, especially for anything on the Known vulnerabilities card. Remove plugins and themes you do not use.
- Change the salts in wp-config.php (secret keys WordPress uses for logins), which signs everyone out, including the attacker.
- On the WP Hardening tab, press Apply Recommended, and consider Disable File Editor and Disable PHP in Uploads if they are not already on.
- Turn on two-factor sign-in for administrators.
Step 6: Check, then keep watching
- Run the malware scan again. It should show no Critical or High findings. Findings that have gone are marked resolved.
- Visit the site as a visitor, including on a phone, and check for redirects or strange content.
- Take a fresh full backup and pin it as your clean starting point.
- Make sure the Malware Detected and Known Vulnerability alerts are on under Alert settings.
- If Google or your host flagged the site, ask them to review it now that it is clean.
Finally, write down what happened, how they got in and what you changed. If the site belongs to a client, they will want to know, and a record helps if it happens again.