Skip to content

How to recover a hacked WordPress site in 7 steps

By William · · updated · 7 min read

A closed laptop on a desk next to paper files
AI-generated image.

Your site is showing a gambling redirect or a red "this site may harm your computer" warning, and you need it back online before you lose more customers. Recover a hacked WordPress site in 7 steps: isolate the site, find the backdoor, clean the database, restore from a clean backup, harden the install, request a Google review, and monitor for reinfection. The order matters because cleaning files before finding the backdoor leaves the site reinfected within days.

Key takeaways

  • Cleaning files before finding the backdoor leaves the site reinfected within days.
  • A free scanner only flags malware it already recognises, so a backdoor is the part it is least likely to catch.
  • If the site is reinfected within 30 days, the backdoor may not have been found in step 2, though new vulnerabilities or credential reuse can also cause reinfection; repeat the file comparison before anything else.
  • Keep at least three off-site backups rotated daily so the next recovery is a restore, not a rebuild.

Isolate the site before you touch anything

Put the site behind a maintenance page or take it offline so visitors stop hitting the redirect and the backdoor stops executing. A maintenance page keeps your domain and email working while the public sees a neutral "we'll be back soon" message instead of the redirect.

Change every credential that could have been exposed: the WordPress admin password, the database password, FTP/SFTP, and the hosting panel. Do this from a clean device, not the one you used to log in while the site was live. If you use the same password anywhere else, change it there too.

Note the exact time you first saw the redirect or warning. You will need it for the Google review request later and for matching log entries when you look for the backdoor. If you are not sure when it started, check your hosting panel's access logs or your own browser history for the first time you saw the warning.

Find the backdoor, not just the visible malware

A free scanner only flags malware it already recognises. A backdoor is a hidden file or code path that lets an attacker return to your site after a cleanup, and it is the part a scanner is least likely to catch. If your site has been cleaned before and hacked again, that is the tell-tale sign of a backdoor that was never found.

Compare every file in wp-content/plugins, wp-content/themes, and the wp-admin folder against a clean copy of the same versions. Download the matching plugin and theme versions from WordPress.org or the vendor, unzip them, and diff the folders. Any file that exists in your install but not in the clean copy is a candidate.

Look for files with random names, recently modified timestamps, or obfuscated PHP that does not belong to any installed plugin or theme. Obfuscated code often looks like long strings of base64 or hex characters. If you cannot tell what a file is for, treat it as suspicious and remove it.

Clean the database and remove injected content

Search the wp_options, wp_posts, and wp_postmeta tables for injected JavaScript, spam links, or hidden admin users. You can do this with a database client like phpMyAdmin or a command-line MySQL client. Search for common patterns such as "eval(", "base64_decode(", and known spam domains.

Delete any user accounts you do not recognise from wp_users. Attackers often create a new admin user so they can log back in after you change your password. Check the user list and remove anyone you did not create.

Remove spam posts, pages, and comments that the attacker added to rank for their own keywords. These often appear as hidden posts with no title or as pages with spammy content. Delete them and check the trash to make sure they are gone.

For a step-by-step walkthrough of the database cleaning process, see How to clean a hacked WordPress database.

Restore from a clean backup instead of patching in place

If you have a backup from before the hack, restore it over the cleaned install; this is faster and less error-prone than deleting files one by one. A backup from the day before the hack is ideal. If your backup is older, you may need to re-enter content created after the backup date.

If you do not have a clean backup, rebuild the site on a fresh WordPress install and import only your content, not the old files. Export your posts, pages, and media from the old database, then import them into the fresh install. This avoids carrying over any hidden files.

WordPress.com includes site recovery as a feature of its service [1]. If your site is hosted on WordPress.com, use their built-in recovery tool instead of manually restoring files.

Harden the install so the same entry point is closed

Update WordPress core, every plugin, and every theme to the latest version before you bring the site back online. Outdated software is a common entry point, but the specific risk depends on which plugin or theme was vulnerable. Update everything you use, and remove anything you do not.

Remove any plugin or theme you no longer use; every unused one is a potential entry point [1]. If you are not sure whether a plugin is in use, check the active plugins list in your WordPress admin. Deactivate and delete anything you do not need.

Set file permissions so wp-config.php is 640 and directories are 755, and disable PHP execution in the uploads folder. You can do this via FTP or your hosting panel's file manager. To disable PHP execution in uploads, add a .htaccess file to the uploads folder with the line "php_flag engine off" or use your hosting panel's security settings.

Request a Google review and clear the search warning

Once the site is clean and back online, submit a review request in Google Search Console so the "this site may harm your computer" warning is removed. Go to the Security Issues section in Search Console and click "Request Review." Include the date and time you first saw the hack and the steps you took to clean it.

Illustration: Request a Google review and clear the search warning

Check that no cached pages still show the redirect; request a re-crawl of the affected URLs. Use the URL Inspection tool in Search Console to request indexing for your homepage and any pages that were showing the redirect.

Monitor Search Console for any new security issues for at least 30 days after the review is approved. If Google flags the site again, the backdoor was not fully removed. Go back to step 2 and repeat the file comparison.

Monitor for reinfection and set a maintenance routine

Run a file-integrity check weekly to catch any new or modified files that do not belong. You can use a plugin like Wordfence or Sucuri, or a command-line script that compares your files against a known-good copy.

Keep at least three off-site backups rotated daily so the next recovery is a restore, not a rebuild. Store backups on a different service from your hosting, such as a cloud storage account or a local drive. Test your backups by restoring one to a staging site at least once a month.

If the site is reinfected within 30 days, the backdoor was not found in step 2; repeat the file comparison before anything else. Do not just clean the visible malware again. Find the backdoor first, then clean.

For a complete checklist you can print and follow, see the WordPress Hack Recovery Guide pack.

Frequently asked questions

What should I do first when I see a redirect?

Put the site behind a maintenance page or take it offline so visitors stop hitting the redirect and the backdoor stops executing.

How do I find the backdoor?

Compare every file in wp-content/plugins, wp-content/themes, and the wp-admin folder against a clean copy of the same versions.

What if I do not have a clean backup?

Rebuild the site on a fresh WordPress install and import only your content, not the old files.

Sources

  1. wordpress.com

Related on this site

This article was drafted with AI assistance and checked before publication.

Free calculator: Website hack downtime cost calculator

The full guide: WordPress Hack Recovery Checklist

Free sample: WordPress Hack Recovery Checklist
Get the free sample now, and new guides by e-mail.