How to clean a hacked WordPress site (step by step)
If your WordPress site has been hacked, you may see strange pages, unknown admin users, spam links in Google results, redirects, or a warning from your browser or hosting provider. This guide shows you how to clean a hacked WordPress site step by step, close the hole the attacker used, and stop it from happening again.
1. Confirm the hack and contain it
- Note the symptoms: which pages are affected, when it started, whether visitors on mobile or from Google see something different.
- Take a full backup of files and database as they are now. See how to back up and restore your website.
- If you have a clean backup from before the infection, restoring it is often the fastest fix. You still need to finish steps 4 to 6, otherwise the attacker gets back in through the same hole.
- Optionally enable a maintenance page while you work so visitors are not exposed to malware.
2. Change every password
- Your cPanel / client area password.
- All WordPress administrator passwords. If you cannot log in, see how to reset your WordPress admin password.
- FTP accounts and the database user password. If you change the database password, update
DB_PASSWORDinwp-config.phpto match. - In Users in WordPress, delete any administrator you do not recognise.
3. Replace WordPress core, themes and plugins with clean copies
- Go to Dashboard > Updates and use Re-install to refresh WordPress core files.
- Delete themes and plugins you do not use. Hackers love abandoned and "nulled" (pirated) plugins.
- Re-install each remaining plugin and theme from the official source (WordPress.org or the vendor) instead of trusting the existing files.
- Never re-use plugins downloaded from piracy sites. They are one of the most common causes of infections.
If WP-CLI is available on your plan, you can verify core and plugin files against the official checksums:
cd ~/public_html
wp core verify-checksums
wp plugin verify-checksums --all
4. Look for backdoors in your files
Attackers usually leave a hidden file so they can come back. Use cPanel File Manager or Terminal and check:
- PHP files inside
wp-content/uploads: this folder should only contain media. - Recently modified PHP files.
- Unknown files in the site root with random names, and changes to
.htaccessandwp-config.php.
cd ~/public_html
find wp-content/uploads -type f -name "*.php"
find . -type f -name "*.php" -mtime -7
Review each result before deleting it. Some legitimate plugins create PHP files too, so if you are unsure, rename it or ask us rather than deleting it.
5. Clean the database
Open phpMyAdmin from cPanel and check:
- The
siteurlandhomevalues in thewp_optionstable (your table prefix may differ). - Posts and pages containing unexpected
<script>tags or hidden spam links. - The users table for accounts you did not create.
6. Close the hole and harden the site
- Update everything: WordPress, plugins, themes and the PHP version (see how to change the PHP version).
- Enable two-factor authentication for administrators and limit login attempts.
- Follow our full checklist on how to secure your WordPress website.
- Set up automatic off-site backups so you always have a clean restore point.
7. Clean up after the hack
- In Google Search Console, check Security issues, and request a review once the site is clean.
- Remove spam URLs that Google indexed (they should now return 404 or 410).
- Watch the site for a few weeks: new admin users, new files, or the same symptoms coming back mean a backdoor is still there.
Common problems
- The hack comes back after cleaning: a backdoor file or a vulnerable plugin was missed. Check uploads, mu-plugins and cron jobs in cPanel.
- Only Google visitors or mobile users see spam: this is a conditional redirect. See how to fix WordPress redirecting to spam sites.
- Site shows a 500 error after cleaning: a needed file may have been removed. See how to fix a 500 Internal Server Error.
Frequently asked questions
Can I just restore an old backup?
Yes, if the backup is from before the infection. But you must still update everything and change passwords, because the original vulnerability is still in the old copy.
Does my hosting scan for malware?
EgWeb servers run server-side security tools that can detect many infected files. They help a lot, but cleaning the database, removing fake users and fixing the vulnerable plugin still has to be done on the site itself.
How do I know which plugin was the entry point?
Check plugins with known recent vulnerabilities, abandoned plugins, and anything pirated. File modification dates and access logs in cPanel can also point to the date and file used.
Need help? Open a support ticket or message us on WhatsApp +20 127 113 3655.