How to Remove Malware From a WordPress Website Without Losing Your Content

How to Remove Malware From a WordPress Website Without Losing Your Content

The identification of malware on your WordPress website can be quite unsettling, considering that it stores years of published content, customer data, images, and other relevant business information. It is a common concern that cleaning up the infection might mean starting all over again with an empty slate.

If your site has been marked by Google for any suspicious activity, then our article “What To Do If Google Says Your Website Has Malware“⁠ will tell you how to interpret the warning and start the investigation.

Thankfully, this is not always the case. WordPress saves a great deal of its content separate from the code files which actually operate the website. What this means is that it is possible to eliminate the contaminated code and restore your blog content without damaging it.

But you need to do it carefully because the wrong deletion of some files, restoring from a bad backup or even missing a pocket of malware can only make things worse for you. The following is a safe way of getting rid of WordPress malware without losing your data.

How to Remove Malware From a WordPress Website Without Losing Your Data

1. Determine the effects of malware on your website

Before you begin removing or altering anything, pause to analyze the situation. Determine the signs of infection and the areas that have been affected on your website.

Indications that a WordPress site has been hacked include:

  • Unwanted redirects to other websites.
  • Unusual advertisements or pop-ups.
  • Administrator accounts created by hackers in your control panel.
  • Unknown files or code present in the website directories.
  • Warnings from Google or your browser about security.
  • Unusual behavior on your server.
  • Website content that you did not create.

Malware may compromise WordPress core files, WordPress plugins, themes, uploads, and database entries. Malware can also create backdoors through which an attacker can gain access to the system even after deleting the malware.

Knowing how big the infection is will help you know what files, database entries, and web parts to look at. This minimizes the chances of removing files that have some of the website content.

According to the WordPress.org hacked-site guide, one is advised to first document any suspicious activities.

2. Backup Your Website Before Deleting Anything

Back up is one of the most critical actions in the malware removal process. No matter how badly your site is infected, you need to make a backup first.

Complete WordPress back up entails two major parts:

  1. Website files: Consists of core WordPress files, plugins, themes, configurations and uploaded content such as images and other documents.
  2. Database: This is where your published posts, comments, users and other settings are stored.

Both parts should be taken into consideration when restoring a WordPress site. Just backing up your files alone won’t ensure that you have backed up all your published material, while just backing up your database alone won’t include your uploaded images.

It may be created by means of the hosting control panel itself, a backup extension, or an SFTP client. In case your hosting company makes automatic backups, find out whether you can access a separate copy of them.

It is recommended to save all your backup files in another place rather than in your hosting account, either on your computer or any other cloud storage site.

Remember that the backup you have made may be infected with malware; hence, you cannot use this backup as a clean version of your website. It is for securing your recently added content and as an insurance measure.

3. Set Website on Maintenance Mode (if required)

When the website redirects users, displays malicious data, or exposes users to threats, you can disable its access temporarily to find out what happened.

Maintenance mode will ensure that the visitors cannot interact with the compromised site as you work on getting rid of the infection. It will also give you ample time to look through all the suspicious files and database entries.

Maintenance mode can be activated using an appropriate WordPress plugin or the hosting environment. In case the infection is serious, check with your hosting provider to know whether you need to isolate the account or website.

Nevertheless, putting a website into maintenance mode will neither eliminate the malware nor prevent an intruder from accessing your hosting account. It is merely a temporary security measure.

Ensure that you have made the backup copy first. If the website is suspended by your hosting company due to some malware, then you should communicate with them to know the next step.

4. Scan Your WordPress Website to Find the Malware

After your website data has been backed up, you need to scan your website to detect any malicious code or potential security holes.

Use an authentic WordPress security plugin that has malware scanning capability. A few tools perform comparison of WordPress core files with their fresh copies and detect any unusual changes. Website scanners outside the site may also be used in detecting any malware or security threats.

However, no one scanner is able to detect all infections. Some viruses are stored within database entries, altered theme files, or unknown folders.

Look especially at:

  • Core WordPress files: Look for any unusual modifications made to critical files located in wp-admin and wp-includes folders.
  • Plugins and Themes: Check for any unknown files, altered code or programs which have not been supported anymore.
  • Uploads directory: Look out for any malicious PHP files or scripts placed in media directories.
  • Database: Search for any unknown administrator accounts, any suspicious scripts, and unauthorised alterations to site content.
  • Configuration files: Inspect files like wp-config.php or .htaccess for any alterations.

Your host may also be able to check the server logs for any unusual activities that could point out when your computer became infected as well as how the hacker got in.

5. Removal of Malware without Losing Website Data

This is the crucial step in the process. The aim is to remove any malicious software without destroying your legitimate website files and other database entries and publications.

Website information is stored by WordPress in various places depending on its nature. Posts, pages, comments, and settings are stored in the database, whereas themes, plugins, media, and application core files are stored on the server. This allows for eradicating most of the infections without having to rebuild the whole website.

Choose the following actions based on the location of the malware:

Replace Infected WordPress Core Files

If the infection occurs in WordPress core files, the affected files need to be restored with clean files by downloading them from the official WordPress releases page. The wp-admin and wp-includes folders can usually be restored with new files corresponding to your WordPress version.

Nonetheless, one should not overwrite all the content inside the wp-content folder and wp-config.php file unless you examine the content inside them first since the wp-content folder is where your themes, plugins, and uploads are stored. On the other hand, wp-config.php holds all the database credentials.

Reinstall Compromised Plugins and Themes

Malicious code can be found in plugins or themes, where you should install a new version of the software directly from the vendor website. First of all, you have to understand if there are some customizations in it which should be preserved.

It is recommended to keep a copy of any customized theme or plug-in prior to its installation. Do not download any premium plug-ins or themes from any unauthorized website as such customized versions could contain malware capable of re-infecting your website.

Remove Malicious Code from the Database

There are some malware attacks that will affect the database of the WordPress website. These include attacks where hackers insert malicious scripts into the content of the site such as pages, posts or even database options. Check through phpMyAdmin to determine any suspicious activities.

Do not delete whole database tables just because they have some unfamiliar records in them. In case of any confusion about a record being malicious, seek help from a WordPress developer.

Check the Uploads Folder

The wp-content/uploads folder contains all your images and documents that are present on your website. However, do not delete the entire uploads folder when trying to remove malware.

You might lose some images that have been published on your website. But check it out for strange executable files, unexplained scripts, and unknown elements. Delete only files that are known to be viruses while retaining valid media files.

However, if the problem is widespread throughout your website or you find it difficult to recognize the malicious codes, you should seek expert help for the removal of malware. Another important tip from WordPress is that it is best to clean your hacked installation without deleting any website contents.

6. Secure Your WordPress Site from Another Infection

Getting rid of the malicious code alone will not secure your site. The site is susceptible to further infection if the vulnerability being taken advantage of by the hacker has not been patched.

After cleaning the infected files and database, do the following:

  • WordPress Update: Install the latest WordPress version compatible with your host.
  • Plugin/Theme Updates: Upgrade outdated software and delete any software that you do not need anymore.
  • Password changes: Change the password of your WordPress administrator, hosting control panel, FTP/SFTP and the database where needed.
  • Look at your user list: Do some spring cleaning, by deleting unknown admin accounts from your system and figuring out what your current users can do.
  • Enable multi-factor authentication: Add another layer of protection to administrator logins.
  • Secure your file permissions: Ensure that your website’s files and directories have their file permissions properly set, in order to avoid leaving them wide open or writable by anyone.
  • Stay with safe programs: Install themes and plugins that can only be downloaded from reputable developers or official websites.

Also, you need to check for any other possibly infected sites within your  hosting account especially if you have more than one site within the same hosting account. If you have multiple websites hosted on one single account, then there is always the possibility that one might infect another.

Some recommendations by WordPress to ensure the security of websites include keeping software up-to-date, implementing access control, using safe themes and plugins, and taking secure backups.

7. Test Your Website after Removing Malware

Do not think that everything is alright just because you can open your website. Test all the main parts of your site to ensure that there were no damages caused by the cleaning process.

Begin by going through your homepage, your articles, pages, images, and any media you have on your site. Make sure that your website navigation and internal links are working properly.

In case there are interactive elements on your website, test them too. They might include:

  • Contact and registration forms.
  • Customer login and account pages.
  • Shopping carts and checkout systems.
  • Search capabilities.
  • E-mail notifications.
  • Booking and payment options.

Perform another scan to verify if any suspicious files or codes are left on your computer. Monitor the activities on your website and any unusual activities on the server logs as well.

In case your website has been marked by Google or some other security service, read the security report accordingly. For Google Search Console, check the Security Issues tab, fix the issues reported, and request a review once the infection has been fixed.

In case you are working on sites where you need to deal with orders from clients and any other regularly changing data, make sure you consider the issue of restoring your databases. If you restore the previous version of your database, all the changes will be erased.

Conclusion

Getting rid of malware does not imply the loss of all the content that you have on your WordPress site since there are certain ways of dealing with it to save all the valuable information on the site.

Nevertheless, removal of malware entails more than deleting the suspect files. There is the need to determine the weakness that enabled the malware to enter the system and secure it from another attack in the future.

Need Reliable WordPress Hosting Service?

Well, then, HarmonWeb will provide you with hosting services that will allow you to have a good and secure control over your website. Select hosting services that have adequate security measures along with the other necessary facilities.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply