ServerNeed — This Year's Best Offers For You

ServerNeed — More Than Hosting
WordPress

How to Clean a Hacked WordPress Site

What to do when WordPress is hacked: contain the damage, find how attackers got in, clean files and the database, rotate every credential and close the hole so it does not happen again.

5 min read 7 views
Screen of numbers with highlighted red characters
Table of Contents
  1. Signs a WordPress site is hacked
  2. Step 1: Contain the damage
  3. Step 2: Find out how the attacker got in
  4. Step 3: Replace core, plugins and themes with clean copies
  5. Step 4: Clean wp-content and the uploads folder
  6. Step 5: Clean the database
  7. Step 6: Rotate every credential
  8. Step 7: Harden and monitor
  9. Step 8: Clear warnings and clean up search results
  10. Should you restore a backup instead?
  11. Frequently Asked Questions
  12. Related reading
  13. Sources

To clean a hacked WordPress site: contain it first (take a backup of the infected state, change passwords, put the site in maintenance mode if it is harming visitors), then replace WordPress core, plugins and themes with clean copies, remove malicious files and database entries, rotate every credential, and fix the weakness that let the attacker in. Cleaning without closing the entry point usually leads to reinfection within days.

This guide follows that order. If the site handles payments or personal data, consider professional help and your legal obligations to notify affected people.

Signs a WordPress site is hacked

  • Visitors are redirected to spam, gambling or fake download sites (often only on mobile or only from search results).
  • Search results show pages or titles you did not create.
  • Unknown administrator accounts appear.
  • Your host suspends the site or reports malware or spam sending.
  • Browsers or Google show a "deceptive site" warning.
  • Files you do not recognise appear, especially .php files in wp-content/uploads.

More general signs are listed in website malware: signs and what to do.

Step 1: Contain the damage

  1. Take a full backup of the hacked site (files and database). You may need it to investigate, and it protects you if cleaning goes wrong.
  2. Change the hosting control panel, FTP/SFTP, database and WordPress admin passwords from a computer you trust.
  3. Put the site in maintenance mode if it is redirecting visitors or serving malware.
  4. Tell your host. They may have logs showing how the attack happened, and they can check whether other accounts are affected.

Step 2: Find out how the attacker got in

Common entry points:

  • an outdated plugin or theme with a known vulnerability;
  • a stolen or weak password, sometimes from another breached site;
  • nulled (pirated) themes or plugins containing backdoors;
  • an infected sibling site in the same hosting account;
  • a compromised computer used to manage the site.

Check plugin and theme versions against their changelogs, review the hosting access logs around the time files changed, and look at the modification dates of suspicious files.

Step 3: Replace core, plugins and themes with clean copies

  • WordPress core: delete everything except wp-config.php and wp-content, then upload a fresh copy of the same or latest version from wordpress.org.
  • Plugins: delete the wp-content/plugins folder contents and reinstall each plugin fresh from its official source. Do not reuse old copies.
  • Themes: reinstall from the official source. If you have a customised child theme, review every file by hand.
  • Remove anything you do not need, including inactive plugins and themes.

Step 4: Clean wp-content and the uploads folder

  • wp-content/uploads should contain media, not PHP. Search for .php files there and remove them (after checking).
  • Look for unfamiliar files in wp-content, such as wp-content/mu-plugins entries you did not create.
  • Check wp-config.php and .htaccess for injected code or redirects; compare them with clean versions.
  • Look for obfuscated code patterns such as long base64 strings combined with eval. Treat these as indicators to investigate, not proof on their own.

A malware scanner from a reputable security plugin, or one provided by your host, helps find known patterns.

Step 5: Clean the database

  • Users: in Users (or the wp_users table), remove any account you did not create, especially administrators.
  • Options: check siteurl and home in wp_options, and look for unexpected scripts in widget and theme option values.
  • Posts and pages: search content for injected <script> tags, iframes or hidden spam links.
  • Scheduled tasks: unexpected cron events can reinstall malware.

Step 6: Rotate every credential

  • All WordPress user passwords (or force resets).
  • Database password (then update wp-config.php).
  • Authentication keys and salts in wp-config.php, which logs everyone out.
  • Hosting, FTP/SFTP and SSH credentials, and any API keys stored on the site.

Step 7: Harden and monitor

Apply the WordPress security checklist: updates, 2FA, least-privilege roles, DISALLOW_FILE_EDIT, a firewall and off-site backups. Then watch closely for a few weeks: file-change alerts, new users, and search results for your domain.

Step 8: Clear warnings and clean up search results

  • If Google flagged the site, request a review in Search Console → Security issues after cleaning.
  • Remove spam URLs that were indexed (they should now return 404 or 410), and submit your sitemap again.
  • If your host suspended the site, ask them to re-scan.

Should you restore a backup instead?

Restoring a clean backup from before the infection can be faster, but you must know when the infection started, and you still need to update everything and fix the entry point. Otherwise the same vulnerability is exploited again. Make sure the backup itself is clean.

Frequently Asked Questions

How do I know the cleanup worked?

Scan again, check for new files and users over the following days, review search results, and confirm security warnings are lifted. Reinfection within a few days usually means a backdoor or the original entry point remains.

Can a hack spread to other sites on my hosting account?

Yes. Sites in the same account usually share file permissions, so check every site in the account, not just the one that showed symptoms.

Do I need to tell my customers?

If personal data may have been accessed, you may have legal obligations depending on your jurisdiction and the data involved. Get advice and be transparent.

Prevention is in the WordPress security checklist, and recovery planning in WordPress backups: what to back up and how to restore. For the WordPress overview, see WordPress hosting: what it is and how to choose. If your ServerNeed account is affected, contact support for logs and help.

Sources

Featured image: “Virus” by Yuri Samoilov, licensed under CC BY 3.0.

Last updated 7 October 2026

View All Articles