How to scan and remove malware from WordPress

WordPress malware is malicious code that attackers hide in your site’s files or database to redirect visitors, send spam or steal data. To remove it, take a full backup, scan with Wordfence and repair or delete the infected files. Then change every password, delete unknown admin users and check for malicious cron jobs.

scan and remove malware from a wordpress website

Removing malware from WordPress is the process of finding and deleting malicious code from your site’s files and database. You scan the site with an online tool or a security plugin, take a backup, clean or replace the infected files and then close the entry point so the infection doesn’t come back.

Any WordPress site, from a small blog to a large e-commerce store, can be targeted by malicious code that slips in through unnoticed vulnerabilities and hidden backdoors.

You don’t need to be a WordPress expert to protect your site from threats. With ongoing effort and knowledge about how malicious code infects files, how to harden WordPress security, and how to effectively scan for and remove malware from WordPress, you can keep your site clean and safe.

I have assisted customers in removing malware from their websites countless times and have encountered a wide range of malicious code that has caused various types of damage to WordPress sites.

In this article, I’ll guide you through every step, from selecting the right security plugins to recognizing signs of malware infection, so you can handle common threats yourself.

If you are a busy business owner and would prefer to have an experienced WordPress developer take care of the problem for you, please check our WordPress malware removal service.

Let’s get started!

Understanding malware and its impact on WordPress

Malware affects WordPress sites by stealing data, defacing pages, sending spam and getting the site blacklisted by search engines. To deal with an infection properly, it helps to know what malware is, what attackers want from your site and why WordPress sites are such a common target.

What is malware?

Malware, short for malicious software, is a broad term that covers all sorts of nasty programs that can infiltrate, damage or exploit websites and computer systems. It includes all sorts of malicious code that serves a specific intent. On a WordPress site, it usually hides in PHP files, .htaccess files or the database.

Purposes of malware

The purposes of malware range from stealing data and taking control of your site to sending spam, attacking other sites and extorting money, and a single infection often serves several of these goals at once. When malware infects a WordPress site, its purposes can vary widely:

  1. Data theft: Malware may be used to steal sensitive information such as login credentials, personal data of users, or financial details.
  2. Website defacement: Attackers might use malware to alter the appearance of your site, displaying unwanted content or propaganda.
  3. Unauthorized access: Malware can create backdoors that allow attackers to gain unauthorized access to your site, enabling them to manipulate or control it. Malware also often phones home to outside servers, so you may want to block unwanted external connections with WordPress’s HTTP API.
  4. Spamming: Some malware is designed to use your WordPress site for sending spam emails or generating unsolicited content.
  5. Distributed Denial of Service (DDoS) attacks: Malware can turn your site into a botnet node, which can be used to launch DDoS attacks against other websites or services.
  6. Monetary gain: Certain types of malware, like ransomware, encrypt your files and demand a ransom for their release, directly targeting your financial resources.
  7. Search engine poisoning: Malware can cause your site to be blacklisted by search engines, affecting its visibility and credibility.

By understanding these malicious intents, you can better safeguard your WordPress site and respond effectively to any security threats.

Why is WordPress vulnerable to malware infection?

WordPress is vulnerable to malware mainly because of its popularity, third-party plugins and themes, skipped updates, weak passwords and insecure hosting. WordPress, while being a powerful and flexible content management system (CMS), is indeed vulnerable to malware attacks for several reasons:

  1. Popularity: WordPress powers a significant portion of the websites on the Internet, making it a prime target for attackers. Its widespread use means that a successful exploit can potentially affect countless sites.
  2. Open source nature: As an open-source platform, WordPress’s code is publicly available. This transparency allows developers to improve and customize the software but also gives potential attackers detailed insights into its inner workings (and possible vulnerabilities).
  3. Plugins and themes: The extensive use of plugins and themes adds endless functionality and design options to WordPress. However, not all of these third-party tools are developed with security in mind. Vulnerabilities in plugins or themes can create entry points for malware.
  4. Requires frequent updates: WordPress core, its themes, and plugins are regularly updated to fix bugs and security issues. Sites that don’t keep their software up-to-date are more susceptible to attacks exploiting known vulnerabilities.
  5. User permissions: WordPress has a flexible user role and permission system. If not configured properly, users with low-level permissions can introduce vulnerabilities or give unauthorized access. The Administrator role should be used sparingly, and you should check the user accounts list from time to time for unknown admin users.
  6. Weak passwords: Many WordPress sites suffer from weak password practices, making it easier for attackers to perform brute-force attacks and gain unauthorized access.
  7. Default settings: Out-of-the-box, WordPress may have default settings and configurations that are not optimized for security. Some of these features, such as XML-RPC, are not used by most websites and should be kept disabled.
  8. Insecure hosting environments: Many WordPress sites are hosted on servers with inadequate security measures. In certain shared hosting environments, one compromised site can affect others on the same server. Attackers can also exploit unprotected folders and files to inject malware.

Addressing as many vulnerabilities as possible is crucial for ensuring the safety and security of your WordPress website.

By systematically identifying and mitigating these potential weaknesses, you significantly reduce the risk of exploitation by attackers. This approach helps protect your site from various threats and ensures its integrity and reliability.

Is your site really compromised or hacked?

If you suspect your WordPress site has been hacked, it’s crucial to verify whether it has truly been compromised to avoid unnecessary troubleshooting. Often, site administrators mistakenly think they have a hacked WordPress site due to issues like a malfunctioning update or spammy comments.

Here are some of the actual signs that indicate your site may indeed be hacked:

  • Unusual spam or random redirections: Spammy content, such as ads for illegal services or inappropriate material, may appear anywhere on your site. This content might be hidden or poorly formatted, making it difficult to spot but still visible to search engines and Google Search Console. Additionally, it may cause unexpected redirections to spammy sites at random times.
  • Unexpected search results: Performing a Google search using site:yourdomain.com might reveal unfamiliar or malicious pages not created by you.
  • User complaints: If users report being redirected to malicious or spammy sites, it’s a red flag. Hacks often hide their activities from site administrators but affect visitors and search engines. Check your site in Incognito mode and through search results rather than directly accessing the URL.
  • Hosting provider alerts: Your hosting provider might notify you if your site is involved in malicious activities, such as being used to redirect spam. Attackers may exploit your site to bypass spam filters by linking to their own sites.

By recognizing these signs, you can better determine if your site has been compromised and take appropriate action. If your site shows a white screen or critical error after an infection, see how to fix the critical error.

Continue reading to find out how to detect malware and deal with a hacked site.

How to scan WordPress for malware

There are different methods you can use to scan and detect malware. Online scanners check your site from the outside, security plugins scan the files on your server, and manual checks catch injections that automated tools sometimes miss. Most cleanups use a combination of all three.

Use online tools to scan WordPress for malicious code

To ensure your WordPress site is free from malware, start by using reputable online tools such as SiteCheck, VirusTotal, or Quttera. These services scan your site for known malware signatures and vulnerabilities, providing a quick assessment of your site’s security status.

SiteCheck and VirusTotal offer thorough scans and detailed reports, helping you identify any malicious code or suspicious files. Quttera also provides insights into potential threats and security issues, allowing you to address them promptly.

Regular use of these tools can help catch malware early, before it causes significant damage.

Remove WordPress malware using a security plugin

Installing a WordPress malware scanner plugin such as Wordfence, Sucuri, or MalCare is essential for ongoing and robust protection of your WordPress site. These plugins offer comprehensive malware scanning and real-time protection, actively monitoring your site for potential threats and vulnerabilities.

Wordfence includes features like a web application firewall (WAF), login security, and live traffic monitoring, while Sucuri provides similar functionalities along with detailed security activity logs and performance enhancements.

By integrating one of these plugins (never install two different security plugins simultaneously as they may conflict) you gain automated malware scanning capabilities and benefit from continuous, proactive defense mechanisms that protect your site against evolving cyber threats.

Conduct manual checks

Manual checks are also essential to ensure a thorough evaluation. Regularly inspecting your website’s files and database for any suspicious code or unauthorized modifications is crucial for maintaining the integrity and security of your site. Even though this method may look more suitable for experienced WordPress website owners, it doesn’t require any coding experience or similar technical ability.

Many infections are easy to spot once you know where to look. When you check the root WordPress installation folder, you will probably be able to identify malware manually by doing basic checks on critical files and folders.

Hackers often exploit vulnerabilities by injecting malicious scripts or altering existing files to compromise your site’s functionality and gain unauthorized access to sensitive data.

These injections are usually found in the first line of important files such as index.php, .htaccess or your theme’s functions.php.

You may also check recently modified files by sorting a folder by date. This will give you a hint what to look for initially.

Preparing for malware removal

Before attempting to remove malware, it’s essential to prepare your WordPress site by taking a full backup of your files and database. This step is important to ensure that your data is safe and can be restored in case something goes wrong, and gives you extra peace of mind.

I highly recommend creating a backup using the UpdraftPlus plugin. Its free version is enough for most purposes and can already send backups to cloud services such as Google Drive, Dropbox or Amazon S3. The Premium version adds more storage destinations and features.

If your WordPress dashboard is not accessible due to malware infection, the only way to back up is through cPanel (or the control panel of your hosting provider).

To proceed with this method, navigate to the File Manager of your control panel and archive your root folder (public_html) to download it as a zip file. Next, navigate to phpMyAdmin and export your WordPress database as a .sql file. This will initiate the download as soon as the export is finished. Keep both files (public_html.zip and yourdatabase.sql) in a safe place on your computer.

Malware removal methods

After creating a backup, you can proceed with the actual WordPress malware removal process. Depending on the type and extent of the infection on your WordPress site, you may use one or both of the following methods. The plugin method is faster, while the manual method is for sites where the dashboard is no longer accessible.

Using a plugin for scanning and malware removal

If your WordPress dashboard is accessible, I recommend that you start with this method. It’s much easier and faster compared to the manual malware removal method. The plugin scans every file for you, and you only need to review what it flags and decide whether to delete or repair each file.

  1. Install a WordPress malware removal plugin like Wordfence, Sucuri, MalCare or Astra Security to scan and remove malware from your site.
  2. Use the plugin’s built-in tools to identify and remove malicious code, and to prevent future attacks.
  3. Configure the plugin to scan your site regularly and provide real-time protection.

Malware removal using the Wordfence plugin

Most security plugins work similarly. But my personal preference is to use Wordfence (free version) for scanning, malware removal and ongoing (real-time) protection. Below you can find screenshots and descriptions from each step. When you install Wordfence, it will require you to enter a license code. It’s free but requires you to enter your email as it sends the license code to your email. Simply follow the directions and complete the setup.

The Wordfence dashboard looks like this after the initial setup:

Right now we are not interested in the Firewall feature, as it is intended for real-time protection rather than scanning and removing malware from your WordPress site. So, click the Scan link in the sidebar and start a new scan by keeping the default scan settings.

This step may take from a few minutes to a couple of hours depending on the number of files in your WordPress installation. During the scan it will list infected files (if found) as well as other security warnings (such as outdated themes and plugins).

Potential malware infections will be marked as Critical and you will be given options to click Ignore or Details.

If you click Details, it will display certain actions to VIEW, DELETE or MARK AS FIXED (if you clean the infection manually via FTP or file manager, without using Wordfence’s interface).

You may go over each file one by one or click DELETE ALL DELETABLE FILES and REPAIR ALL REPAIRABLE FILES to remove a large number of infections at once.

In my experience with Wordfence, I found that the automated delete and repair functions work amazingly well, and there are very few false positives.

In the rare case that Wordfence incorrectly repairs a file, you can always restore it from the backup that you’ve created while preparing the site for malware removal.

After removing and repairing all infected files, repeat the scan to ensure there are no more infections, and visit your website to check if everything functions properly.

Manual malware removal

In some cases, injected malicious code may prevent your access to the WordPress dashboard through your regular dashboard URL (yourdomain.com/wp-admin). If the cause is malware-injected .htaccess files in every folder, you can remove them with a cleanup script instead of rebuilding the whole site.

To proceed with the manual malware removal method and regain access to your WordPress dashboard, you should have control panel access (usually cPanel) or FTP access to your web hosting account.

Here are the steps you need to follow:

  1. Using your control panel’s File Manager or your FTP client, navigate to public_html.
  2. Copy or move the wp-config.php file and wp-content folder to a folder that is located in the parent folder of public_html (for example, if your WordPress files are in the /public_html folder, copy wp-config.php and wp-content to /backup).
  1. Download the latest version of WordPress from WordPress.org.
  2. Delete ALL files and folders within public_html, including all hidden files such as .htaccess. If other sites live in subfolders of public_html, keep those folders and clean them separately.
  3. Before proceeding, make sure public_html is completely empty and does not contain any hidden files (hidden file names start with a dot). Request help from your hosting provider if you have difficulty deleting certain files or folders.
  4. Upload a fresh copy of WordPress core files into public_html and unzip them. Make sure these files do not reside in a subfolder inside the root folder such as public_html/wordpress. Move them if necessary.
  5. Before you copy wp-content back, delete the plugins and themes folders in your backup copy and plan to reinstall fresh copies from WordPress.org or the vendor. Then look for PHP files inside wp-content/uploads, since that folder should only contain media.
  6. Copy your wp-config.php file and wp-content folder back to their original location in the public_html folder. This may require overwriting the original wp-content folder that came with the zip file. That’s okay. Just overwrite and proceed.
  7. Edit or view your wp-config.php file, compare it with wp-config-sample.php and ensure that there is no malicious code in it.

These steps overwrite your core WordPress files and remove any injected malicious code found in your root folder, as well as the wp-admin and wp-includes folders. Hopefully, your dashboard should be accessible now.

As we wiped out all files in your root folder (/public_html) in the previous step, we need to regenerate the .htaccess file that is necessary for the correct URL structure of your WordPress website.

To do this, log in to the WordPress dashboard, navigate to Settings > Permalinks and click Save Changes. That’s all.

You can now continue with the steps in the “Using a plugin for scanning and malware removal” method.

After the cleanup: close the door behind you

After the cleanup, you need to close every way back in: passwords, security keys, admin accounts, cron jobs and the database. Most reinfections happen because one of these steps was skipped. Once your site is clean, work through this list:

  • Change every password: hosting, FTP/SFTP, database and all WordPress administrators.
  • Replace the security keys and salts in wp-config.php. This logs everyone out, including the attacker.
  • Check Users for administrator accounts you don’t recognize and delete them.
  • Check for malicious cron jobs in your hosting control panel. We once found one re-infecting l10n.php every minute.
  • Search the database for injected <script> tags in posts and options, and make sure siteurl and home in the wp_options table are correct.

How to prevent future malware attacks

Preventing future attacks is just as important as removing malware from your WordPress site, because a cleaned site with the same weak spots usually gets infected again. Whenever I perform a fresh WordPress installation, I immediately implement the following precautions as part of the initial setup to enhance security.

  • Activate auto-update for plugins and themes.
  • Use strong passwords and enable two-factor authentication to prevent unauthorized access.
  • Remove any unused administrator accounts.
  • Remove unused plugins and themes. Try to keep your WordPress installation as lean as possible.
  • Install a security plugin to provide real-time protection and monitoring.
  • Put a firewall in front of your site with Cloudflare’s free WAF rules.
  • Regularly scan your site for malware and suspicious activity. (Wordfence does this automatically and warns you.)
  • Check your PHP version and upgrade to the latest one that is compatible with your theme and plugins.
  • Change the WordPress dashboard URL from yourdomain.com/wp-admin to something hard to guess, and disable unused WordPress features that increase the attack surface. The WP Hide and Security and Perfmatters plugins do this job perfectly.
  • Schedule regular backups and keep backup files on a remote cloud service or locally on your computer. The UpdraftPlus plugin is highly recommended.
  • Ensure your web hosting environment is secure by choosing a reputable hosting provider that offers robust security features, or consider using professional WordPress maintenance plans for comprehensive care.

What is Google Safe Browsing?

Google Safe Browsing is a security service that helps protect you from bad websites and online threats. It scans the web constantly for unsafe sites that might have malware, phishing or other bad stuff. When you try to visit a site that’s marked as unsafe, Google Safe Browsing will show you a warning message telling you what the danger is.

It’s integrated into many Google products like Google Chrome, Google Search and Android as well as other browsers and apps.

On search results, you will see a message similar to “This site may be hacked” beneath the URL.

If you click the link and try to access the website, then Google Chrome will show the “Deceptive site ahead” warning.

Google warnings stay until you request a review

When Google finds malware on your site, visitors see security warnings in search results and in their browsers. The site can lose a lot of traffic and reputation, as users are scared off by these warnings. The warnings don’t expire on their own. They stay until you remove all malware, secure the site and request a review from Google. Malware reviews usually take a few days.

Be thorough before you ask for that review. If your site keeps switching between clean and infected within a short time, Google can classify it as a repeat offender, and you have to wait 30 days before you can request another review. This is why it’s so important to have good security practices to protect both site visitors and the site itself.

How to remove the Google malware warning from your site

Removing the Google malware warning takes three steps: clean the site, check the issue in Google Search Console and request a review. Google only lifts the warning after it confirms the site is clean, so finish the cleanup first and send the review request last.

  • Initially, I recommend putting your site into maintenance mode to prevent further damage and protect visitors. You can use any maintenance mode plugin to do this.
  • Next, you should follow the steps discussed in this article to scan, detect and remove malware from your WordPress site.
  • If you have already claimed your website in Google Search Console, log in to your Google Search Console account to check for security issues. Google will often specify the type of malware detected and the affected pages, and send you a notification email regarding the issue.
  • If not, visit https://search.google.com/search-console/about and follow the steps to add your domain to your Google Search Console account.
  • After removing malware from your WordPress site, go back to Google Search Console and navigate to the Security issues section.
  • Click the Request Review button. Explain the steps you’ve taken to remove the malware and secure your site.
  • Google will review your site, which may take a few days. If they find that your site is clean, they will remove the malware warning.

Key takeaways

Removing malware from WordPress comes down to four steps: back up, scan, clean and harden the site. Here’s a short summary of what this guide covers, so you can come back to it the next time you need to deal with an infected site.

  • Removing malware from your WordPress site requires careful preparation, detection, and removal.
  • By following the steps outlined in this article, you can effectively remove malware from your site and prevent future attacks.
  • Remember to always take a full backup of your site, use a reliable security plugin, and keep your WordPress core files, plugins, and themes up-to-date.
  • If your website shows a “Deceptive site ahead” warning in Google Chrome, you may request a review in Google Search Console after you secure your website.
  • See how we cleaned up a real infection in our Ski Georgia case study.

About the author

Ozgur Sar Avatar