How to Clean a Hacked WordPress Website: A Step-by-Step Recovery Guide
Finding out your site has been compromised is a digital nightmare, but knowing how to clean a hacked WordPress website efficiently can save your business from long-term damage. When security is breached, hackers may inject malicious scripts, redirect your traffic, or steal sensitive user data. Beyond the immediate technical risk, a hack can lead to your site being blacklisted by search engines, causing a total collapse in organic traffic. This guide provides a comprehensive, professional approach to identifying the breach, scrubbing the infection, and hardening your site against future attacks.
1. Stay Calm and Enter Maintenance Mode
The moment you suspect a hack, you must act quickly but methodically.
Isolate the Site: If you have multiple sites on one hosting account, the infection could spread.
Enable Maintenance Mode: Use a plugin or a manual .htaccess rule to show a “Coming Soon” page. This prevents visitors from seeing a broken or dangerous site.
Document Everything: Take screenshots of weird behavior or error messages. This can help if you need to consult a security professional later.
2. Identify the Symptoms of a Hack
Before you can fix the problem, you need to understand the nature of the breach. Common signs include:
Sudden Traffic Spikes or Drops: Often caused by “Japanese Keyword Hacks” or hidden redirects.
Unfamiliar Admin Users: Check your WordPress “Users” list for accounts you didn’t create.
Google Search Warnings: If Google displays “This site may be hacked” in search results, you have a confirmed issue.
Technical Errors: Occasionally, a hack causes specific server issues like the 403 forbidden error in WordPress because the malware has altered your file permissions.
3. The Cleanup Process: Step-by-Step
To effectively clean a hacked WordPress website, you must address both the files and the database.
Step A: Manual File Inspection
Hackers often hide code in the wp-config.php file, the .htaccess file, and the wp-content/themes folders.
Re-install WordPress Core: Delete all core files (keep wp-config.php and wp-content) and replace them with a fresh download from WordPress.org.
Check the Plugins Folder: Delete all plugins and re-install them from the official repository. Never use “nulled” or pirated premium plugins.
Step B: Clean the Database
Malicious links and “backdoor” scripts are frequently hidden in your database tables.
Search for Keywords: Use a tool like WP-CLI or phpMyAdmin to search for common malicious strings like eval, base64_encode, or stripslashes.
Audit Your Tables: Look for suspicious content in the wp_options and wp_posts tables.
4. Reset All Credentials
Once the code is clean, you must lock the doors.
Change All Passwords: This includes WordPress admin, FTP/SFTP, and your hosting control panel.
Salt Your Keys: Update the “Secret Keys” in your wp-config.php file. This will force-log out every current session.
Cleaning the site is only half the battle; you must prevent a recurrence.
Update Everything: Outdated themes and plugins are the leading cause of WordPress hacks.
Web Application Firewall (WAF): Use a service like Cloudflare or Sucuri to block malicious traffic before it even reaches your server.
Image Security: Ensure you optimize images for web performance using trusted plugins, as malicious code can sometimes be hidden in metadata.
Consult Expert Documentation: Follow the WordPress Hardening Guide for advanced server-level security tips.
6. Request a Review from Google
After you are certain the site is clean, you need to tell the search engines.
Search Console: Go to the “Security Issues” tab.
Request Review: Detail exactly what steps you took to remove the malware. Google usually reviews and removes the blacklist warning within 24 to 72 hours.
7. The Importance of Backups
The easiest way to clean a hacked WordPress website is to restore a clean backup from before the infection occurred.
Off-site Backups: Never store backups on the same server as your website.
Automated Schedules: Set up daily backups so you never lose more than 24 hours of work.
Conclusion
Recovering from a hack is a stressful and technical process, but by following these steps, you can regain control of your digital presence. Start by isolating the site, scrubbing the files and database, and finishing with robust security hardening. Remember, security is an ongoing commitment, not a one-time fix.