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.

Table of Contents
- Signs a WordPress site is hacked
- Step 1: Contain the damage
- Step 2: Find out how the attacker got in
- Step 3: Replace core, plugins and themes with clean copies
- Step 4: Clean wp-content and the uploads folder
- Step 5: Clean the database
- Step 6: Rotate every credential
- Step 7: Harden and monitor
- Step 8: Clear warnings and clean up search results
- Should you restore a backup instead?
- Frequently Asked Questions
- Related reading
- 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
.phpfiles inwp-content/uploads.
More general signs are listed in website malware: signs and what to do.
Step 1: Contain the damage
- 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.
- Change the hosting control panel, FTP/SFTP, database and WordPress admin passwords from a computer you trust.
- Put the site in maintenance mode if it is redirecting visitors or serving malware.
- 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.phpandwp-content, then upload a fresh copy of the same or latest version from wordpress.org. - Plugins: delete the
wp-content/pluginsfolder 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/uploadsshould contain media, not PHP. Search for.phpfiles there and remove them (after checking).- Look for unfamiliar files in
wp-content, such aswp-content/mu-pluginsentries you did not create. - Check
wp-config.phpand.htaccessfor 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_userstable), remove any account you did not create, especially administrators. - Options: check
siteurlandhomeinwp_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.
Related reading
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
- WordPress Documentation: FAQ My site was hacked
- Google Search Central: Security issues and hacked sites
Featured image: “Virus” by Yuri Samoilov, licensed under CC BY 3.0.
Last updated 7 October 2026



