How to Recover a Hacked WordPress Website

Blog

Throughout my long experience as a web developer, I have always found WordPress to be one of the most reliable and versatile platforms compared to countless alternatives. I’m Tony M John, and I have been involved in the website development field since 1996. Being an ardent observer of the evolution of website technologies over the years, WordPress still stands atop my list to date due to its open-source nature, large plugin library, and supportive and friendly community. However, no system is without imperfections, especially when it comes to the aspect of security on WordPress websites - the improper implementation of safeguards, or a lack thereof, can cause the website to get hacked! I have faced this firsthand, and while it is tribulating, there is a way to recover the website, and I have used this method a few times successfully. Throughout this blog, I will walk you through how to recover a hacked WordPress website successfully through four simple steps.

Confirm If Your WordPress Site Is Hacked (Early Detection)

The initial step that one must take is to verify that your site has been hacked. Occasional misconfigurations or hosting issues may cause problems across the website that resemble cyberattacks. Prompt identification of such signs can allow you to take swift action. The following factors can indicate that your website may be compromised:

  • Your Website Won’t Load: If your website has suddenly become inaccessible or is redirected to the following error pages - 404, 403, or 500 - you must check your server logs to see if someone has made any file modifications or errors. Typically, hackers manipulate core files to cause further server issues, which you can observe in your server logs. To verify this, you can check on Google PageSpeed Insights to see whether the website’s loading speed or performance rate is being affected by malware planted by the hackers.

  •  Your Website Gets Redirected to Another Website: One of the most obvious signs that your website has been hacked is that it gets redirected to another website. You can verify the situation by checking your .htaccess or index.php files for errors or suspicious codes left by the hackers. To further verify this, you can head to the Security Issues section on the Google Search Console to check if there are any vulnerabilities with the security or any mentions of redirect exploits.

  • Suspicious Google Warnings and Blacklist Alerts: Employing Google Safe Browsing to check your website can state whether it has been flagged for malicious content. Typically, malicious content can appear on the website as extra content that can be in other languages or unwanted ads - a sign of SEO spam malware injection.

  • Strange Admin Users or Implementations of Unknown Plugins: Hackers often create new admin accounts so that they can regain access to the website. You can check this by visiting the admin panel and checking for suspicious user accounts. This can be avoided by implementing the following WordPress plugins:

    • iThemes Security
    • Wordfence

Unusual Traffic Drops and Slow Website Performance: Hackers often use malware, which affects the website performance and traffic rates due to immense bot traffic. You can check this using Google Analytics or Cloudflare Analytics to look for traffic spikes from unspecified sources.


Take Immediate Action to Limit Damage

The above steps can help you verify whether your website has been compromised. Now that you've confirmed the compromise, it's time to move on to the second step: containing and limiting the damage done to your website. The longer a site is online, the more it can harm visitors, data, or the brand's reputation. Here’s what can be done to minimize the impact of hacking and secure your website:

  • Enable Maintenance Mode to Protect Visitors: By enabling maintenance mode, you can prevent further damage from hacking and data theft. You can enable maintenance mode by installing the following plugins:

      • SeedProd
      • WP Maintenance Mode

  • Change All the Passwords: It is crucial that you change all the passwords for the following credentials:

    • WP Admin
    • cPanel
    • FTP
    • MySQL
    • Hosting Accounts

You can use a password manager to generate strong and unique passwords and even utilize 2-factor authentication for stronger security.

  • Inform your Hosting Provider: I have noticed that many hosting providers, especially - Kinsta, SiteGround, and Bluehost, often provide server-level malware removal services. You can reach out to their teams for help.

  • Scan for Malware and Suspicious Files: Malware can spread across the website and hide in the code. You can use the following plugins to sweep through the code and detect malicious files and scripts:

      • Sucuri SiteCheck
      • VirusTotal
      • Wordfence Security Scanner

  • Check for Recent File Updates: Hackers focus on core WordPress files to install malware codes. This step helps them gain easy access and control over your website. Check. Here’s where you should check for unauthorized updates and modifications to the website script:

    • wp-content/uploads
    • wp-config.php
    • .htaccess


Recover and Clean Your Hacked WordPress Site

After you secure your website, it is time to move on to the next step. This stage involves the complete recovery of all the lost data and the removal of all traces of malware or suspicious codes from your website. The following steps can bring your site back to its original and completely functioning state:

  • Restore from a Clean Backup (If Available): If a clean backup is available, cross-check the backup to verify that it is clean and not compromised. You can use the following tools for safe website restoration:

      • UpdraftPlus
      • Jetpack Backup
      • BlogVault

  • Manually Remove Malware from Core Files: You can manually go through the code using cPanel File Manager or FTP - Filezilla. By checking for suspicious code patterns - base64, eval, gzinflate, or other suspicious code in the PHP files, you can manually remove the infected sections and secure the code.

  • Remove Suspicious Database Entries (SQL Cleanup): Using the phpMyAdmin plugin, you can review key tables - wp_posts, wp_options, and wp_users for spammy content. Hackers frequently conceal malicious code and spammy links within these tables, so it's important to remove such content when necessary. Make sure that you save a backup copy before saving the changes to avoid further issues.

  • Reset WordPress Security Keys (Force Logout All Users): It is crucial that you complete this step to log out all users and eliminate compromised sessions. You can create new security keys for your website using the WordPress.org Secret Key Generator, which will strengthen its security.

  • Reinstall WordPress Core and Plugins (Without Losing Data): The final process in this step involves downloading a fresh copy of WordPress and replacing core files on your server while keeping the wp-content folder and wp-config.php file intact. This process makes sure that your prior configurations are transferred with the new copy. 


Strengthen WordPress Security to Prevent Future Attacks

In my experience, a lot of people tend to skip this step as they have already recovered their website. However, recovering your website is simply the first step. Only employing proactive measures can help you safeguard your websites from hackers and malware. Here’s what you must do to prevent future attacks:

  • Install a Security Plugin (Active Monitoring): Implement security plugins that stay active, such as Wordfence, Sucuri, or MalCare, which offer firewall protection, malware scanning, and real-time monitoring. These plugins can also alert you to other suspicious activities or vulnerabilities.


  • Enable Two-Factor Authentication (2FA) for Admins: 2FA or 2-Factor Authentication can help you form an extra layer of protection. By requiring a one-time code from trustworthy apps like Google Authenticator or Authy, you can stay safe even if someone acquires your password.

  •  Block XML-RPC & Limit Login Attempts: You can disable XML-RPC through the .htaccess file. This functionality can be instrumental in preventing automated brute-force attacks and pingback exploits. Additionally, pairing this with the Limit Login Attempts Reloaded plugin can help in restricting login retries and blocking hacker IPs on multiple attempts.

  •  Secure File Permissions & Disable PHP Execution in Uploads: Enabling file permissions can enhance security and restrict unauthorized access. You can also disable PHP execution, which can be helpful in preventing malicious scripts.

  • Switch to a Secure Hosting Provider: When you choose a hosting provider, ensure that they provide comprehensive security services - firewalls, malware scanning, and daily backups. Some of the hosting services that I recommend are:

    • Cloudways
    • WP Engine
    • Kinsta

  • Schedule Automated Offsite Backups: Using plugins like UpdraftPlus, BlogVault, and Jetpack can help you store backups in external locations, away from the site server, on Google Drive or AWS. This ensures that your backup remains safe and easy to restore whenever required. 

When to Hire an Expert for WordPress Malware Removal

While DIY solutions can work to an extent, not every malware or hacking issue should be handled alone. Basic cleanups and scans can be done alone, but some situations may arise when you require help from professionals to protect your site, users, and brand reputation. Hackers are constantly evolving and using the latest technologies to hide codes and malware deep within the system. Knowing when to call an expert can save you from recurring attacks and legal issues. The following are situations or signs when you must call in a professional:



  • If Malware Keeps Coming Back (Reinfections): Persistent infections can arise due to vulnerabilities hidden deep within the code. These can be missed by normal scans and require professional help.

  • If Google Blacklisted Your Website: Being blacklisted by Google can severely impact your traffic, credibility, and online reputation. An expert can find the proper solution for this issue and guide you through the Google Search Console process to request, review, and regain your site’s visibility.

  • If Legal or Financial Data is Compromised: If your website handles sensitive data, a breach can lead to serious legal consequences. Professionals can work promptly to offer you the perfect solution that minimizes liability. 

Conclusion

Throughout my 25 years of experience as a digital marketer involved in web development, WordPress has been a go-to choice for building flexible, scalable, and user-friendly websites. With popularity comes an increased risk of cyberattacks, and protecting your WordPress website has become a mandate rather than a choice. By recognizing early signs of malware, taking prompt actions, and re-evaluating to implement stronger security measures, you can minimize downtime and safeguard your digital presence and reputation. When it comes to a situation where you feel helpless, do not hesitate to reach out to a WordPress professional. As a business owner, I understand the pressure of keeping your website active and running smoothly while managing other elements. Investing in the right help at the right time can be fundamentally helpful in protecting your brand and reputation, in addition to your peace of mind.