WordPress malware removal means finding every infected file and database entry, cleaning or replacing it, removing the backdoors the attacker left behind and closing the hole they used to get in. Deleting the single file your scanner flagged is rarely enough, because malware usually hides in several places at once. This guide covers the cleanup itself. If you are still deciding what to do first, start with our WordPress site hacked checklist.
What WordPress malware removal actually involves
Malware rarely lives in one spot. A proper cleanup checks three areas:
- Files: WordPress core, plugins, themes, the uploads folder and loose files in the site root.
- Database: injected scripts in posts and options, spam content, unknown administrator users and odd scheduled tasks.
- Server settings: .htaccess rules, PHP configuration files and cron jobs that reload the infection after you remove it.
If you only clean one of these, the infection usually comes back within days.
Before you start: take a safe copy
- Download a full backup of the files and the database, even though it is infected. It is your evidence and your fallback if a cleanup step breaks something.
- Put the site in maintenance mode or restrict access if it is serving spam or redirects to visitors.
- Save your hosting access logs if you can. They help you find how the attacker got in.
If you do not have a recent clean backup, read our guide to backing up and restoring a WordPress site first.
Step 1: Find what changed
Run a scan with your host’s malware scanner or a reputable security plugin, but do not rely on it alone. Scanners miss custom backdoors. If you have SSH access, WP-CLI can compare your core and plugin files against the official versions:
wp core verify-checksums
wp plugin verify-checksums --all
Any file reported as modified or unexpected deserves a closer look. Premium plugins and themes are not covered by the plugin check, so inspect those manually.
Step 2: Replace core, plugins and themes with clean copies
Replacing files is safer than editing infected code by hand. Keep wp-config.php and the uploads folder, replace everything else.
wp core download --force --skip-content
- Delete each plugin and theme folder, then reinstall a fresh copy from the official source or your licence account.
- Remove plugins and themes you no longer use instead of just deactivating them.
- Never reinstall “nulled” or pirated plugins. They are a common source of infections.
Step 3: Clean the uploads folder and loose files
The uploads folder should hold images and documents, not PHP code. These commands help you spot what does not belong:
find wp-content/uploads -name "*.php"
find . -type f -name "*.php" -mtime -7
A PHP file inside uploads is almost always suspicious. Recently changed PHP files you did not touch are worth checking too, but remember that legitimate updates also change files.
Step 4: Clean the database
- Search posts, pages and options for unexpected script tags, base64 strings and unfamiliar iframes.
- List administrator accounts with
wp user list --role=administratorand remove any you do not recognise. - Check scheduled tasks with
wp cron event listfor jobs you did not create.
Export the database before any search and replace. A careless query can damage legitimate content.
Step 5: Hunt for backdoors
Backdoors are the reason reinfection happens. Check these locations:
- Unknown files in the site root and in
wp-content/mu-plugins. - Unexpected drop-in files such as
wp-content/object-cache.phpthat you never set up. - Strange rules in .htaccess, or an
auto_prepend_fileline in .user.ini or php.ini. - Other sites on the same hosting account, which can reinfect yours.
Step 6: Reset every credential
Change WordPress admin passwords, the database password, SFTP and hosting panel logins, and regenerate the security keys in wp-config.php. Do this after the cleanup, not before, or the attacker may still hold a working session.
Step 7: Close the entry point and harden the site
Malware removal without a fix for the original weakness is only a pause. Update everything, delete unused code and turn off the built-in file editor by adding define( 'DISALLOW_FILE_EDIT', true ); to wp-config.php, as recommended in the WordPress hardening guide. Our WordPress security best practices article covers the rest.
Clean the site or restore a backup?
Restoring a backup works only if it predates the infection and you also fix the entry point. If you cannot tell when the infection started, cleaning the current site and verifying it step by step is the safer route.
Quick checklist
- Full backup taken and logs saved
- Core, plugins and themes replaced with clean copies
- No PHP files in uploads, no unknown admin users or cron jobs
- Backdoor locations checked
- All passwords and security keys changed
- Entry point found and closed, site re-scanned
When to get professional help
Get help if the infection keeps returning, if you cannot find the backdoor or if customer data may be exposed. Our WordPress fixes and troubleshooting service covers cleanup, and our maintenance plans keep updates and backups under control afterwards. With 10+ years of WordPress experience, a Top Rated badge on Upwork and a 100% Job Success score, I handle these cases regularly. Contact us and we reply within 24 hours.
Frequently Asked Questions
Will a security plugin remove malware automatically?
It can detect known patterns and clean some of them, but it can miss backdoors and heavily modified files. Treat the scan as a starting point and verify the result manually.
How do I know the malware is really gone?
Core and plugin checksums pass, no unexpected PHP files remain, no unknown users or cron jobs exist and a fresh scan is clean. Keep watching your logs for a few days afterwards.
Will Google remove its security warning after cleanup?
Not automatically. Once the site is clean, review any security issue in Google Search Console and request a review.
Further reading: WordPress.org documentation: FAQ My site was hacked.