WordPress malware infections share common patterns: injected admin users, modified core files, backdoor scripts, and database spam. This checklist walks you through detection, removal, and hardening in a methodical order. Work through each section to confirm your site is clean and secured against reinfection.
Before You Begin
Before touching the live site, prepare your environment and gather baseline information.
Take a Full Backup
Even if the site is compromised, you need a snapshot before making changes. Backup both files and database.
tar -czf backup-$(date +%F).tar.gz public_html/
mysqldump -u username -p database_name > backup-$(date +%F).sql
Store backups outside the web root and download a copy locally.
Document Current State
Note visible symptoms: redirects, spam content, defacement, performance issues, or blacklist warnings. Check Google Search Console and site health tools for warnings.
Access Your Hosting Control Panel
Confirm you have cPanel, Plesk, or direct server access. You'll need FTP/SFTP credentials, SSH access if available, and database access through phpMyAdmin or command line.
Isolate If Necessary
If the site is serving malware to visitors or sending spam, take it offline temporarily with a maintenance mode plugin or by renaming the public directory. Balance visitor impact against ongoing harm.
Step 1: Scan for Malware
Run multiple scanners to catch different infection types. No single tool finds everything.
Use WordPress Security Plugins
Install and run:
- Wordfence Security: Deep file scan comparing against WordPress.org repository checksums
- Sucuri Security: Malware scanner with known signature database
- MalCare: Automated detection and optional cleanup
Each plugin will report modified core files, suspicious PHP in themes and plugins, and database injections. Export or screenshot results for reference.
Run Server-Side Scanners
If you have SSH access, run ClamAV or maldet (Linux Malware Detect).
# ClamAV scan
freshclam
clamscan -r -i /home/username/public_html/
# maldet scan
maldet -a /home/username/public_html/
Server scanners catch obfuscated PHP and known exploit signatures that WordPress plugins might miss.
Check for Common Malware Locations
Manually inspect high-risk directories:
wp-content/uploads/for PHP files (uploads should only contain media)wp-includes/for extra PHP files not part of core.htaccessfor redirect ruleswp-config.phpfor injected code before or after legitimate config- Theme
functions.phpfiles for base64-encoded injections
Look for recently modified files:
find public_html/ -type f -name "*.php" -mtime -7 -ls
Search for Known Malware Patterns
Grep for common signatures:
grep -r "eval(base64_decode" public_html/
grep -r "gzinflate" public_html/
grep -r "preg_replace.*\/e" public_html/
grep -r "shell_exec" public_html/
grep -r "assert(" public_html/
Note every match for investigation.
Step 2: Identify the Infection Vector
Understanding how attackers got in prevents reinfection.
Check Access Logs
Review Apache or Nginx access logs for suspicious POST requests, unusual user agents, or requests to obscure PHP files.
grep "POST" access_log | grep -E "\.(jpg|png|gif|zip)\.php"
Look for patterns around the first infection date.
Review User Accounts
Check WordPress admin users for unauthorized accounts:
SELECT * FROM wp_users;
SELECT * FROM wp_usermeta WHERE meta_key = 'wp_capabilities';
Delete any unknown administrator accounts immediately.
Audit Plugins and Themes
List all installed plugins and themes. Cross-reference against WordPress.org to identify:
- Nulled (pirated) plugins and themes — common malware vectors
- Abandoned plugins with known vulnerabilities
- Outdated versions with public exploits
Remove anything you don't recognize or can't verify.
Check File Permissions
World-writable files and directories allow attackers to modify code:
find public_html/ -type f -perm 0777
find public_html/ -type d -perm 0777
Core WordPress files should be 644, directories 755, and wp-config.php should be 440 or 400.
Step 3: Clean Infected Files
With malware identified, begin systematic removal.
Reinstall WordPress Core
Replace core files with clean copies from WordPress.org. Do NOT delete wp-content or wp-config.php.
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
cp -r wordpress/* public_html/
Or use WP-CLI:
wp core download --force --skip-content
This overwrites wp-admin and wp-includes with clean versions.
Reinstall Plugins
Delete and reinstall all plugins from official sources:
wp plugin delete --all
wp plugin install [plugin-slug] --activate
For premium plugins, download fresh copies from the vendor. Never reuse potentially infected copies.
Reinstall or Clean Themes
Delete all themes except a clean default theme:
wp theme delete --all
wp theme install twentytwentyfour --activate
If you must keep a custom theme, manually review every PHP file for injected code. Look for:
- Base64-encoded strings
- Obfuscated variable names
- Functions like
eval,assert,create_function - Unexpected
includeorrequirestatements
Remove Malicious Files
Delete any PHP files in wp-content/uploads/:
find wp-content/uploads/ -type f -name "*.php" -delete
Review and remove any suspicious files identified during scanning.
Clean .htaccess
Replace with a clean WordPress .htaccess:
# BEGIN WordPress
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Check for redirect rules or strange directives above or below the WordPress block.
Sanitize wp-config.php
Open wp-config.php and verify every line. Remove:
- Code injected before the opening
<?phpor after the closing?>(if present) - Base64-encoded strings
- Unexpected
include,require, orevalstatements
A clean wp-config.php should only contain database credentials, table prefix, authentication keys, and ABSPATH definition.
Step 4: Clean the Database
Malware often injects spam into posts, comments, and options.
Remove Rogue Admin Users
Delete unauthorized administrator accounts:
DELETE FROM wp_users WHERE user_login = 'suspicious_admin';
DELETE FROM wp_usermeta WHERE user_id NOT IN (SELECT ID FROM wp_users);
Scan for Injected Content
Search post content for suspicious patterns:
SELECT ID, post_title FROM wp_posts WHERE post_content LIKE '%<script%' OR post_content LIKE '%<iframe%';
Manually review and clean affected posts.
Check wp_options Table
Malware often modifies site URL, home URL, or active plugins:
SELECT * FROM wp_options WHERE option_name IN ('siteurl', 'home', 'active_plugins', 'admin_email');
Verify values are correct. Look for suspicious entries in active_plugins.
Remove Spam Comments
Delete spam comments in bulk:
DELETE FROM wp_comments WHERE comment_approved = 'spam';
Clean Malicious Cron Jobs
Check for backdoor cron jobs:
SELECT * FROM wp_options WHERE option_name = 'cron';
Delete the entire cron option to reset, or use:
wp cron event list
wp cron event delete [hook-name]
Step 5: Harden WordPress Security
Prevention is cheaper than cleanup.
Update Everything
Ensure WordPress core, all plugins, and themes are current:
wp core update
wp plugin update --all
wp theme update --all
Enable automatic updates for minor releases.
Change All Passwords
Reset passwords for:
- All WordPress users (especially administrators)
- Database user
- FTP/SFTP accounts
- Hosting control panel
Use strong, unique passwords stored in a password manager.
Regenerate Authentication Keys
Replace salts in wp-config.php using the WordPress.org secret key generator. This invalidates all existing sessions and forces reauthentication.
Restrict File Editing
Disable the theme and plugin editors:
define('DISALLOW_FILE_EDIT', true);
Add this to wp-config.php above the ABSPATH line.
Set Correct File Permissions
find public_html/ -type d -exec chmod 755 {} \;
find public_html/ -type f -exec chmod 644 {} \;
chmod 440 public_html/wp-config.php
Install a Security Plugin
Keep Wordfence or Sucuri active for ongoing monitoring, firewall protection, and malware scanning. Configure email alerts for login attempts and file changes.
Implement Two-Factor Authentication
Use a plugin like Two-Factor or Wordfence to require 2FA for administrator accounts.
Limit Login Attempts
Install a plugin that blocks brute force attacks by limiting login attempts and implementing temporary lockouts.
Disable XML-RPC If Unused
XML-RPC is a common attack vector. Block it via .htaccess:
<Files xmlrpc.php>
Order Deny,Allow
Deny from all
</Files>
Hide WordPress Version
Remove version info from your site's HTML:
remove_action('wp_head', 'wp_generator');
Add to your theme's functions.php.
Set Up a Web Application Firewall
If your host offers ModSecurity or a similar WAF, enable it. Cloudflare's free tier provides additional protection at the DNS level.
Step 6: Monitor and Verify
Confirm the cleanup was successful and establish ongoing monitoring.
Test Site Functionality
Browse the site as a visitor and administrator. Check forms, login, checkout, and any custom functionality.
Verify With External Scanners
Run free online scans:
- Sucuri SiteCheck
- VirusTotal URL scanner
- Google Safe Browsing status
Wait 24-48 hours and rescan to confirm no new infections appear.
Check Blacklist Status
If your site was blacklisted, request review:
- Google Search Console: submit reconsideration request
- Norton Safe Web: submit re-evaluation
- McAfee SiteAdvisor: request URL review
Provide details on steps taken to clean and secure the site.
Set Up File Integrity Monitoring
Configure your security plugin to alert on file changes. Review alerts promptly to catch new compromises early.
Schedule Regular Scans
Run malware scans weekly and after any plugin or theme updates.
Review Logs Regularly
Check access logs and security plugin logs weekly for suspicious patterns.
When to Restore From Backup
If the infection is extensive, the entry point unclear, or you lack confidence in manual cleanup, restoring from a clean backup is faster and more reliable. Choose a backup from before the first infection date, restore it, then immediately apply security hardening steps.
Conclusion
Removing malware from WordPress requires methodical work: scan comprehensively, clean thoroughly, and harden aggressively. The checklist above provides a concrete path from detection through prevention. After cleanup, maintain discipline with updates, backups, and monitoring. Security is not a one-time task but an ongoing practice. A clean site today requires the same vigilance tomorrow to stay that way.
