Trusted Bespoke Software & eCommerce Solution Developers

Trusted Bespoke Software & eCommerce Solution Developers.

Fix Hacked WordPress Website: A Step-by-Step Guide to Removing Malware

Picture this: You wake up one morning, eager to check your WordPress website’s performance and engage with your audience. But as soon as you open your site, you’re greeted with an unfamiliar homepage, spammy links, or even a glaring red warning from Google stating that your website is potentially harmful.

If you’re nodding your head in grim recognition, you’ve experienced every website owner’s worst nightmare – a hacked WordPress site. The panic, frustration, and fear that follow a hack are enough to make anyone’s heart race.

But don’t worry; you’re not alone, and there’s a solution. In this comprehensive guide, we’ll walk you through the step-by-step process of fixing a hacked WordPress website. We’ll also show you how to bolster your site’s security to prevent future attacks, giving you the peace of mind to focus on what truly matters – your website’s content and your audience.

So, take a deep breath, pour yourself a cup of coffee, and let’s get started on the journey to reclaiming your website from the clutches of malicious hackers.

Understanding the Hack: What You Need to Know

Before we dive into the technical aspects of cleaning up a hacked WordPress site, it’s crucial to understand how to recognize the signs of a compromise. Early detection can mean the difference between a minor inconvenience and a major catastrophe.

  1. Suspicious Changes in Website Appearance: A hacked site may feature unfamiliar content, often with links to unrelated or questionable websites. Your site’s layout might change, and you may notice pop-up ads or defaced pages.
  2. Sudden Traffic Drops: Search engines or web browsers may flag your site as potentially harmful, leading to a sharp drop in traffic. Be on the lookout for reduced organic search traffic, often indicated by a noticeable dip in your website’s analytics.
  3. Google Safe Browsing Warning: If Google identifies malware on your site, they’ll warn visitors that it’s potentially harmful. Users will see a red warning screen discouraging them from proceeding.
  4. Unwanted Redirects: Hacked sites often employ malicious redirects, sending your visitors to unrelated or spammy websites. This negatively impacts your site’s credibility.
  5. Unexpected Email Alerts: Sometimes, your web hosting provider may send you an email warning of suspicious activities or malware detected on your server.

By staying vigilant and recognizing these signs, you can act swiftly when a hack occurs, minimizing potential damage and reducing downtime.

Immediate Steps: Responding to a Hacked Website

When you’ve confirmed that your WordPress website has been hacked, it’s essential to act swiftly to minimize the damage. Here are the immediate steps to take:

  1. Isolate Your Website: If possible, take your website offline. This prevents further damage and ensures that visitors won’t encounter security warnings while you work on the fix.
  2. Scan Your Computer: Before you start diagnosing your website, scan your own computer for malware. Malicious software on your computer can make it easier for hackers to access your site. Use reputable antivirus and anti-malware tools for a thorough scan.
  3. Change Passwords: Change all your passwords – for your WordPress admin, hosting account, FTP, and your database. Use strong, unique passwords that include a combination of upper and lower-case letters, numbers, and special characters.
  4. Contact Your Hosting Provider: Notify your hosting provider about the breach. They may offer guidance or assistance, and they can help you assess the impact of the hack.
  5. Backup Your Site: If you have a recent clean backup of your website, consider restoring it. Be cautious, though – ensure that the backup isn’t compromised. You’ll need to clean the backup files if they are.
  6. Remove Unknown Users: Check your WordPress user list for any unfamiliar or unauthorized users. Remove them immediately. Also, review and reset the roles and permissions of existing users, ensuring they only have access to what’s necessary.

Identifying the Type of Hack

Understanding the type of hack your website has suffered is crucial for effective remediation.

Based on the SiteCheck Website Malware Trends: Mid-Year 2023 Report shared by Sucuri, injected malware and redirects were the most common infection followed by SEO Spam.

As per Sucuri’s report:In the first half of 2023, SiteCheck scanned a total of 54,743,804 websites. From this number, we detected 628,085 infected sites, while another 851,164 sites were found to contain blocklisted resources.

Types of malware that infect WordPress Websites
Most common types of Malwares. Source: Sucuri

Hackers often exploit LFI vulnerabilities to compromise WordPress websites. This type of vulnerability allows attackers to manipulate website URLs to include files from the server’s local file system. In doing so, they can access sensitive files, execute arbitrary code, and potentially escalate their privileges, posing a significant threat to the security of your WordPress site. To prevent these vulnerabilities, it’s crucial to stay informed and implement security measures to safeguard your website.

Let’s look at the most common infections


Backdoors are a common way hackers break into WordPress sites, granting them secret access even after you’ve fixed other issues. Here are just a few of the issues that backdoors can cause on your site:

  1. Unauthorized access to your site’s content and user data
  2. Installation of malicious scripts and code
  3. Spammy links and ads being added to your site without your knowledge
  4. Redirection of your site’s traffic to malicious sites

Malware’s impact on your website is significant. It tarnishes your online reputation, disrupts search engine rankings, and slashes your business revenue. Don’t underestimate its potential damage.

In most cases of this type of infection, we find a modified index.php & .htaccess and extra files or even folders being created. You will also notice that the file permissions are also changed to 444 so that the owner of the file is also not able to make modifications to the file.

[Resolved] How to fix backdoor infected WordPress website index.php
WordPress Malware attack modified index.php file
[Resolved] How to fix .htaccess infected by WordPress malware
WordPress Malware attack modified .htaccess file
[Resolved] Additional files added by backdoor attack on WordPress websites, know how to fix it.
Additional files added in Backdoor WordPress Hack

Malicious Redirects

A redirector malware may modify the siteurl/homeurl settings for the WordPress website, causing the website to redirect to a spam or a scam website. Hackers use this technique to capitalize on the existing traffic of the website and scam website visitors.

SEO Spam

SEO spam typically manifests as undesired keywords, spammy content, ads, or malevolent redirects to the attacker’s website. Attackers employ tactics like link injections, spam comments, or generating new posts/pages on compromised sites. Notably, these attacks can affect websites on various content management systems (CMS) such as WordPress, Joomla, Drupal, or Magento.

If left untreated, an SEO spam infection can lead to blocklisting by Google and other major search authorities — which can significantly damage website rankings, reduce organic traffic, and negatively impact reputation. If you operate an ecommerce store, an infection can result in lost revenue and even impact your PCI DSS compliance if data is breached.

As a result of these infections search results may be polluted with Japanese keyword spam, as seen in these recent examples below:

How to fix SEO Spam malware attack on WordPress website

Restoration Process: How to Fix a Hacked WordPress Site

The restoration process can be tricky, depending on the severity of the infection. First and foremost, try to access your WordPress admin dashboard.

If you can access the WordPress admin, click here to go to the next step.

Assuming, you are not able to access the WordPress backend, either you see a page not found page or else redirected to the home page. In this case, depending on if you have access to cpanel or FileZilla/SSH access, access the project root folder.

[Resolved] How to restore a hacked WordPress website.
FileZilla - FTP Client

Take a complete backup of your current site, if not taken already. Check if both index.php and .htaccess files have been corrupted completely. In some cases, the .htaccess file is changed and a base64 encoded string is added to the index.php file.

In case the scripts are partially modified, update your .htaccess file shown below.

[Resolved] How to fix an infected .htaccess file that keeps regenrating.
Fix .htaccess file

At this stage, if you are not technically sound, you need to contact an expert – At Madgeek, we help resolve WordPress security issues.

Try accessing the WordPress admin dashboard again, If you can access the WordPress admin, click here to go to the next step.

Assuming, the .htaccess and index.php files have been regenerated. Which is a sign of backdoor attack. 

Usually, in a backdoor attack, the file permissions are changed to avoid the files being modified by the owner – permission is set to 444.

Access your SSH terminal or using FileZilla change the permissions.
Go to the project root and run the below command:

					chown www-data:www-data  -R * # Let Apache be owner
find . -type d -exec chmod 755 {} \;  # Change directory permissions rwxr-xr-x
find . -type f -exec chmod 644 {} \;  # Change file permissions rw-r--r--


Also, a common practice of backdoor attacks is to add a .htaccess file in each and every folder. Keeping a backup of the .htaccess file in the project root folder, run the below command from your SSH terminal.

The command below will recursively find all the htaccess files in the project root and delete them.

					find . -name ".htaccess" -exec rm -rf {} \;

In most cases, this should fix the issue and you should be able to access the WordPress admin, If you can access the WordPress admin, click here to go to the next step.

Often it happens that the corrupted files keeps regenerating, that’s because the injected script added a cron job or else a process.

Try disabling WordPress cron by adding the below line to your wp-config.php

					define('DISABLE_WP_CRON', true) ;

Re-fix the .htaccess and index.php files, if the corrupted files still regenerate, open your terminal and close the process (I personally don’t prefer this process as it’s difficult to find the injected process).

If you are using the Ubuntu server, run the below command to look for process activities. If you can trace the process which is regenerating the corrupted files, kill the process and reupload the fixed files.

Ubuntu top command

If this still doesn’t fix the problem, replace the complete project setup.

Find the current version of WordPress your website is running on by going to project root > wp-includes > version.php and open the version.php file in a file editor.


Go to the WordPress releases list and download the same version on your local system.

Except for the wp-content folder and wp-config.php from the project root, delete all the folders and files. Upload all the files and wp-includes and wp-admin folders from the local system of the WordPress release. (It will be best to create a fresh project root to avoid corrupted files from regenerating.)

[Resolved] How to fix a hacked WordPress website and setup a fresh app.
Delete all files and folders except for wp-config.php and wp-content

This should fix the issue and you will be able to access the WordPress admin dashboard, If you can access the WordPress admin, click here to go to the next step.

Scan Your Website

Use a security plugin or an online scanning service to identify and remove malicious code. Some reputable plugins include Wordfence, Sucuri Security.

Install Wordfence and run a complete website scan. Remove malware files detected by the plugin or repair them.

WordPress malware removal service.

Manually Remove Malicious Code

Inspect your website’s files and database for suspicious code. This can be a time-consuming process, but it’s essential for thorough cleaning.

[Resolved] How to restore a hacked WordPress website.
FTP client

Update WordPress and all plugins

Ensure that your WordPress core, themes, and plugins are up to date. Sometimes, outdated files contain vulnerabilities that hackers can exploit.

If your WordPress version is outdated and the theme or plugin used doesn’t support the latest version of WordPress or PHP, you need to consult an expert.

Remove Unauthorized Users

Double-check and clean your user database, removing any unauthorized or unfamiliar users.

Change All Passwords Again

Reset all passwords, even those you changed earlier. It’s a precautionary measure to prevent re-entry.

Preventing Future Hacks: Strengthening Security

Once you’ve successfully cleaned your hacked WordPress website, it’s time to focus on long-term prevention:

  1. Regular Backups: Set up automated backups and ensure you have a clean backup from which you can restore in case of future hacks.
  2. Security Plugins: Install reputable security plugins to protect your site from attacks and provide real-time monitoring.
  3. Firewall: Implement a web application firewall (WAF) to filter and block malicious traffic.
  4. Stay Updated: Keep your website’s core, themes, and plugins updated to patch vulnerabilities.
  5. Regular Scans: Schedule regular security scans and audits to detect vulnerabilities and potential threats.
  6. Strong Authentication: Enforce strong password policies and consider two-factor authentication for all users.
  7. Educate Your Team: If you have multiple users, educate them about website security best practices.

By following these steps, you can not only fix a hacked WordPress website but also fortify it against future threats. Remember, website security is an ongoing process, and staying vigilant is key to safeguarding your online presence.

Conclusion: Restoring Your Peace of Mind

A hacked WordPress website can be a disheartening experience, but it’s not the end of the road. With the right approach and tools, you can regain control and ensure your site remains secure. Remember to stay updated, be vigilant, and invest in comprehensive security solutions. Your website’s health and your peace of mind are worth the effort. By following the steps outlined in this guide, you have taken significant strides towards restoring your website’s security and your confidence in its resilience. 

In the realm of web security, prevention, preparedness, and consistent monitoring are your most potent allies. With the right approach and a commitment to ongoing maintenance, you can turn the page on a hack, learning valuable lessons along the way. Keep your website secure, stay updated, and enjoy the peace of mind that comes with knowing that you’ve taken concrete steps to protect your digital asset. Your website, your business, and your reputation depend on it.


A .htaccess hack involves unauthorized access to your website’s .htaccess file, often leading to website redirects or display of unwanted content. To fix it, access your website files via FTP, locate the .htaccess file, and remove any suspicious code. Replace it with a clean version or update your website’s core files if necessary.

A backdoor attack installs unauthorized access points on your site, allowing hackers to re-enter even after removal. To fix it, start by identifying and removing any suspicious files or folders in your WordPress installation. Next, change all WordPress passwords, including admin, FTP, and database passwords. Finally, update all plugins, themes, and the WordPress core to the latest versions.

Japanese SEO spam involves injecting Japanese keywords and links into your site’s content, often damaging your site’s SEO and reputation. To address it, scan your website thoroughly using a reputable security plugin or service to identify infected files or database entries. Remove these malicious links and keywords manually or use specialized tools provided by security plugins.

To protect your site, start by implementing robust security measures, including regular updates of WordPress core, themes, and plugins. Install a reputable security plugin, enable a website firewall, regularly scan for malware, and perform routine backups. Additionally, utilize strong passwords, limit login attempts, and employ two-factor authentication for added security.
Unusual content or unexpected redirects might indicate a hack. It’s crucial to take immediate action. Start by installing a reputable security plugin and performing a malware scan. Additionally, contact a professional service to conduct a thorough security audit and resolve any issues quickly to prevent further damage to your site’s reputation and user trust.

If your WordPress website’s .htaccess or index.php files are being regenerated unexpectedly, it’s a sign of a possible compromise. Here’s what you can do to address this issue:

  1. Take your website offline: Immediately take your website offline to prevent further alterations or damage.
  2. Change passwords: Change all passwords associated with your WordPress site, including admin credentials, FTP, hosting, and database access.
  3. Scan for malware: Use a reputable security plugin or software to run a thorough malware scan. Identify any malicious files or scripts causing the regeneration of these files.
  4. Check file permissions: Ensure that file permissions for .htaccess and index.php are correct. They should typically be set to 644 for files and 755 for directories.
  5. Audit .htaccess file: Carefully review the .htaccess file content for any unauthorized or suspicious code. Remove any unfamiliar code that doesn’t belong to your site.
  6. Restore from backups: If you have clean backups available, restore your .htaccess and index.php files from a version before the hack occurred.
  7. Seek professional help: If you’re unsure about the steps or the situation persists, it’s highly recommended to seek assistance from a security expert or a professional WordPress developer who specializes in website security. They can conduct a detailed audit, remove malware, and reinforce your site’s security to prevent future incidents.


Remember, it’s crucial to address these issues promptly and thoroughly to ensure your website’s security and prevent further compromise or damage.

A WordPress redirect hack is a type of attack where cybercriminals manipulate your website’s settings or files to redirect visitors to malicious or spammy sites. This hack can significantly damage your site’s reputation and impact its SEO.

To fix a WordPress redirect hack:

  1. Identify the hack: Look for unexpected redirects when visiting your site. Check the site’s URL in search engine results to see if it’s displaying different content than expected.
  2. Scan for malware: Use reliable security plugins or online scanners to perform a thorough scan of your WordPress site. Detect and remove any malicious code, scripts, or unfamiliar files.
  3. Review recent changes: Analyze recent updates, installations, or modifications to themes, plugins, or the WordPress core. Malicious redirects might stem from compromised or outdated software.
  4. Check .htaccess and theme files: Review your site’s .htaccess file and theme files for suspicious code. Look for unfamiliar redirects, unusual code snippets, or injected scripts that don’t belong.
  5. Update WordPress and plugins: Ensure that WordPress, themes, and plugins are up-to-date. Vulnerabilities in outdated software can be exploited, leading to hacks and redirects.
  6. Remove malicious redirects: Manually remove any unauthorized or suspicious redirects from your site’s files or settings. Clean and restore affected files from a known clean backup.
  7. Secure your site: Strengthen your website’s security by using strong passwords, implementing two-factor authentication, limiting login attempts, and installing reputable security plugins.
  8. Request a malware review: After cleaning your site, request a review from search engines like Google to remove any warnings or flags associated with your website due to the hack.


If you’re uncertain about fixing the WordPress redirect hack yourself or need further assistance, consider seeking professional help from experienced WordPress security experts to ensure your site is thoroughly cleaned and secured against future attacks.

Abhijit Das
CEO & Co-Founder
Table of Contents

Are you looking for a reliable & trustworthy technology vendor for your organization?

These brands trust us for their enterprise app & modernization requirements.

Recommended Posts

Let’s transform your business

We have successfully launched 50+ apps for businesses from all around the world. We take pride in our ability to deliver quality apps on time and within budget.