Hacked WordPress website? A step-by-step recovery guide
If you think your WordPress site has been compromised, the order you do things in matters. These are the steps I’d take, in the order I’d take them, and the point at which it’s worth getting help.
1. Confirm the signs and write down what you see
Typical signs are visitors redirected to other sites, spam pages or links you didn’t add, a warning from your browser, host or Google, unfamiliar administrator users, being locked out, or your host suspending the site. Note what you see, where and when it started. Screenshots help.
Check the site from a phone on mobile data and in a private window. Some malware only shows itself to visitors arriving from search results or to people who aren’t logged in.
2. Don’t make it worse
Avoid deleting files at random or restoring over the top of the site before you’ve saved anything. You may lose the evidence of how it got in, or delete something the site needs.
Tell your host as soon as you can. They can often confirm what they’ve detected and may have their own backups. If the site is harming visitors, consider putting it into maintenance mode or temporarily taking it offline.
3. Back up the current state, then find a clean backup
Take a full copy of the files and database as they are now, even though they’re infected, and keep it separate. It is useful for investigating, and it protects you if a clean-up goes wrong.
Then look for the most recent backup from before the problem began. Your host’s backups are usually safer than a plugin on the compromised site. A restore only helps if the backup predates the infection and the way in is closed afterwards.
4. Change every password and remove unknown users
Change the passwords for your hosting account, WordPress administrators, the database, FTP or SFTP, and any email account tied to the site. Do it from a device you trust, and use a unique password for each.
In Users, remove or demote any administrator you don’t recognise, and check that the email address on genuine accounts hasn’t been changed. Turning on two-factor sign-in for administrators is worthwhile.
5. Find out what has changed
Compare WordPress core, plugins and themes against clean copies. The Site Health screen, a reputable security scanner and your host’s malware scanner can all help. Look for recently modified files, unfamiliar files in the uploads folder, odd code in theme files such as functions.php, and unexpected scheduled tasks.
Don’t rely on a single scan. Scanners miss things, and a clean result doesn’t prove the site is clean.
6. Clean or restore
The safest approach is to reinstall WordPress core, plugins and themes from their official sources, and remove anything you can’t account for. Then check the wp-content folder, the database and the .htaccess file for injected code or links.
If you restore a clean backup instead, update everything straight away and do steps 4 and 7. Otherwise whatever let the attacker in the first time will do so again.
7. Close the way in
Common causes are outdated plugins or themes, abandoned plugins, weak or reused passwords and nulled (pirated) software. Update everything, delete anything you don’t use, and replace plugins that are no longer maintained.
Also check file permissions with your host, and whether other sites on the same hosting account were affected, because one infected site can reinfect another.
8. Check the site and the warnings
Test the pages, forms, checkout and logins, as cleaning can break things. Check the site as a visitor, including on mobile, and look in Google Search Console for security issues.
If your host, a browser or Google flagged the site, you can usually ask for a review once it’s clean. How long it takes to clear is up to them, not you.
9. Reduce the chance of a repeat
Keep WordPress, plugins and themes updated, keep regular backups stored away from the site, give each person only the access they need and use two-factor sign-in. Check your admin users and installed plugins every so often.
None of this guarantees a site can never be compromised again, but it removes the most common ways in.
When to stop and get help
Get help if malicious code keeps coming back, you can’t log in, your host has suspended the site, or the site takes payments or holds customer information. For questions about your obligations if customer information may have been exposed, ask your host or a professional adviser.
Most compromised sites can be cleaned, but not every one can be fully recovered, and no clean-up can promise a site won’t be targeted again.
Rather hand it over?
Tell me what you’re seeing, include your website address and say if it’s urgent. I’ll reply with any questions and tell you what I think it needs.