WordPress is the most popular content management system in the world, which also makes it a prime target for hackers. Malware infections can compromise your website, steal sensitive data, damage your SEO rankings, and harm your visitors. If your WordPress site has been hacked, acting quickly is essential to minimize damage. This step-by-step guide will walk you through identifying, removing, and preventing malware infections, ensuring your site is secure and fully functional again. Following these steps not only restores your site but also improves its resilience against future attacks.
1. Identify Signs of Malware Infection
Before removing malware, you need to confirm that your website has indeed been compromised. Common signs include: unexpected redirects, unknown admin accounts, strange code in files, unusual spikes in traffic, slow performance, and warnings from Google Safe Browsing. You may also notice unauthorized posts or pages appearing on your site. Checking error logs, scanning for suspicious files, and using security plugins like Wordfence or Sucuri can help identify the malware source. Understanding the signs early allows you to respond effectively and prevents further damage.
2. Backup Your Website Before Cleanup
Even if your site is hacked, creating a full backup is crucial. Backup both your database and all WordPress files. This ensures you have a fallback in case anything goes wrong during the malware removal process. Plugins like UpdraftPlus or BackupBuddy can simplify this task. Always store backups off-site or in cloud storage, not just on your server, to avoid losing them in case of server compromise. A clean backup also helps compare infected and clean files to detect malicious changes.
3. Put Your Website in Maintenance Mode
During cleanup, it’s important to prevent visitors from accessing the compromised site. Putting the site in maintenance mode avoids spreading malware and maintains your professional reputation. Plugins like WP Maintenance Mode or SeedProd allow you to display a temporary message while you work. This step also protects your users from potential infections while you perform the necessary cleaning and security measures.
4. Scan Your Website for Malware
Scanning your website helps pinpoint the infected files. Use trusted security plugins such as Wordfence, Sucuri Security, or MalCare. These tools detect malicious code, suspicious file changes, and infected themes or plugins. Scanning manually is also possible by reviewing the wp-content directory and wp-config.php file for unusual code, especially base64 encoded strings or hidden iframe injections. Combining automated and manual scanning ensures no malware goes unnoticed.
5. Check and Clean Core WordPress Files
Hacked websites often have modified WordPress core files. Replace these files with fresh copies from the official WordPress repository. Pay special attention to wp-config.php, index.php, .htaccess, and files in the wp-admin and wp-includes folders. Compare file hashes if possible. Never overwrite the wp-content folder unless absolutely necessary, as it contains your themes, plugins, and uploads. Cleaning core files restores the integrity of your WordPress installation and removes common entry points for hackers.
6. Remove Infected Plugins and Themes
Malware frequently hides in outdated or nulled plugins and themes. Deactivate all plugins, then reactivate only those you trust. Delete any plugins or themes not in use, and replace pirated versions with legitimate copies. Update all active plugins and themes to their latest versions. Using secure, regularly updated extensions reduces the risk of reinfection. For guidance on keeping plugins safe, check our post on Common WordPress Errors and Solutions.
7. Clean Your Database
Malware can inject malicious code into your WordPress database, often in the wp_posts, wp_options, or wp_users tables. Use phpMyAdmin or a database plugin to review entries for suspicious scripts, unknown admin accounts, or unexpected links. Backup your database before making changes. Removing malware from the database ensures that infections hidden in content, settings, or user data are eliminated, preventing reinfection after cleaning files.
8. Remove Unauthorized Users and Reset Passwords
Hackers often create new admin accounts to maintain access. Review all users in the WordPress dashboard and remove any suspicious accounts. Reset passwords for all remaining users, including FTP, database, and hosting accounts. Use strong passwords with a combination of letters, numbers, and symbols. Implementing two-factor authentication (2FA) adds an extra layer of security, making it harder for attackers to regain access.
9. Clean Up .htaccess and Other Configuration Files
Malware often modifies the .htaccess file to create redirects or inject malicious code. Review this file and remove any unknown rules. Also, check wp-config.php and other configuration files for suspicious code. Ensure permissions are properly set (644 for files, 755 for folders) to prevent unauthorized changes. Cleaning these files eliminates common backdoors and restores your site’s configuration to a safe state.
10. Scan and Optimize Media Files
Hackers may inject malware into uploaded images, PDFs, or other media files. Review the wp-content/uploads folder for suspicious files. Delete any files you don’t recognize and scan the rest using security plugins. Converting all media to secure formats and avoiding direct executable uploads (like .php) can prevent reinfections. Optimizing images also improves site performance after cleanup, complementing your security efforts.
11. Update WordPress Core, Themes, and Plugins
Once malware is removed, update WordPress, all active themes, and plugins to the latest versions. This step closes known vulnerabilities that hackers exploit. Enable automatic updates for minor WordPress releases to maintain security over time. Always verify that updates come from official sources to avoid installing compromised files. For detailed guidance, see our post on How to Restore a Website from Wayback Machine to WordPress.
12. Install a Security Plugin for Ongoing Protection
Prevention is better than cure. After cleaning your website, install a security plugin to monitor for future threats. Plugins like Wordfence, Sucuri Security, or MalCare provide real-time scanning, firewall protection, malware removal, and login security. Configure alerts to notify you of suspicious activity. Continuous monitoring ensures that malware is detected and removed quickly, preventing serious damage.
13. Enable Firewall and Brute Force Protection
A Web Application Firewall (WAF) blocks malicious traffic before it reaches your website. Most security plugins include this feature, or you can use services like Cloudflare or Sucuri. Limit login attempts and enforce strong passwords. Protecting your site from brute force attacks and automated login attempts reduces the risk of reinfection and keeps your site running smoothly.
14. Verify Clean Website with Online Scanners
After cleanup, verify that your site is malware-free using online tools. Services like Google Safe Browsing, VirusTotal, or Sucuri SiteCheck can detect remaining infections. If your site is blacklisted, follow the process to request a review from Google or other search engines. Verification ensures your visitors and search engines recognize your site as safe, restoring trust and search rankings.
15. Regular Backups and Maintenance
Finally, prevent future infections by creating a maintenance routine. Schedule automatic backups, update WordPress core, themes, and plugins regularly, and perform periodic security scans. Educate users on strong passwords and limit admin access. Following a maintenance plan, similar to our WordPress Website Maintenance Checklist, ensures your site remains secure and reduces the impact of potential attacks.
Conclusion
Removing malware from a hacked WordPress site can seem overwhelming, but following this step-by-step guide ensures a complete cleanup. By identifying infections, removing malicious files and database entries, securing your site, and implementing ongoing monitoring, you protect both your website and your visitors. Security is an ongoing process—regular backups, updates, and audits are essential for maintaining a fast, safe, and reliable WordPress site.