You open your website and find strange pop-ups, a redirect to a gambling page, or a Google warning that says “This site may be hacked.” Perhaps your host has suspended the account for sending spam. Whatever the symptom, the feeling is the same: panic.
Take a breath. A hacked WordPress site can almost always be recovered, and you do not need to be a security expert to do it. This guide shows you how to remove malware from WordPress safely when your site runs on your own VPS, dedicated server, or hosting account. You will learn how to recognize an infection, run a malware scan on the server, clean the files and database, close the hole the attacker used, and keep it from happening again.
Quick Answer: How Do You Remove Malware From WordPress Site?
To remove malware from a WordPress site, back up the infected site, put it into maintenance mode, scan files and the database, replace WordPress core, plugins, and themes with clean copies, delete unknown files and users, change every password and key, update everything, and then harden the site and server.
The short version of the process:
- Contain the damage and take a backup.
- Confirm the infection and find the malicious files.
- Replace core files, plugins, and themes with fresh copies.
- Clean the uploads folder, database, and configuration files.
- Remove backdoors and unknown admin users.
- Change all credentials and security keys.
- Fix the original vulnerability.
- Request review from search engines if you were flagged.
- Harden WordPress and the server, then monitor.
Common Signs That Your WordPress Site Is Hacked
Malware does not always announce itself. Many infections are designed to stay hidden from the site owner while still harming visitors. Watch for these warning signs:
- Unexpected redirects, especially for visitors who arrive from Google or on mobile devices, while the site looks normal to you
- Spam content or links, such as pharmacy, casino, or counterfeit-goods pages, sometimes only visible to search engine bots
- Google Search Console warnings, such as “Hacked content” or “Security issues”
- Browser warnings like “Deceptive site ahead”
- New administrator accounts that you did not create
- Unknown files or plugins, or files with odd names in the uploads or root folders
- Sudden traffic or CPU spikes, or a host warning about resource abuse
- Outgoing spam email or blacklisting of your server IP
- Defaced pages or changed homepage content
- Slow performance with no clear reason
- You cannot log in, because the attacker changed your password or removed your admin access If you see any of these, assume compromise until you prove otherwise.
Step : Stay Calm and Contain the Damage
Before you touch anything, do the following:
- Do not delete the site in a panic. You may destroy the evidence needed to find the entry point.
- Put the site into maintenance mode or restrict access with a simple password on the web server, so visitors are protected and the attacker cannot keep using the site.
- Tell your host if the server hosts other sites, since an infection can spread across accounts.
- Take a full backup of files and the database, even though it is infected. Store it away from the web root. You may need it for forensics, and it protects you if the cleanup goes wrong.
- Note the time when you first noticed the problem. It helps you find files changed around that time.
VPS Server Plans
Explore IT4INT VPS server plans for reliable, high-performance hosting with fast SSD storage, Linux and Windows OS options, full root access, scalable resources, and 24/7 technical support. Choose a VPS hosting plan that fits your website, application, or business needs.
Step 1: Scan the Server and Confirm the Infection
A thorough malware scan on the server should cover both WordPress and the operating system level, because attackers often plant files outside the WordPress folder.
Use a WordPress security plugin
Plugins such as Wordfence, Sucuri Security, or Patchstack can scan core files, plugins, and themes and highlight modified or suspicious code. If you cannot log in to the dashboard, scan from the command line instead.
Use server-side scanners
On a VPS or dedicated server with shell access, run scanners directly:
- ClamAV for general malware signatures
- Linux Malware Detect (Maldet) which includes signatures aimed at web shells and PHP malware
- Imunify360 or similar tools, if your host provides them
- rkhunter or chkrootkit to look for server-level rootkits
sudo clamscan -r –infected /var/www/yoursite
Scanners miss things, so treat the results as a starting point, not a final verdict.
Verify WordPress core and plugin files with WP-CLI
WP-CLI can compare your files against the official checksums:
wp core verify-checksums
wp plugin verify-checksums –all
Any file reported as modified or unexpected in core deserves close inspection. Premium plugins and themes are not covered by the public checksums, so compare them against a fresh download from the vendor.
Search for recently changed files
find /var/www/yoursite -type f -name “*.php” -mtime -7
This lists PHP files changed in the last seven days. Adjust the number to match the date of the first symptoms.
Check for PHP files in places they should not be
The wp-content/uploads folder should contain images, documents, and media, not PHP scripts. Find them with:
find /var/www/yoursite/wp-content/uploads -type f -name “*.php”
Any result is suspicious.
Look for common malicious code patterns
Malware often uses functions that hide or execute code. Search for suspicious patterns such as base64_decode, eval(, gzinflate, str_rot13, assert(, and preg_replace with the /e modifier:
grep -rIl –include=*.php -E “eval\(|base64_decode\(|gzinflate\(” /var/www/yoursite
Be careful: some legitimate plugins use these functions. Do not delete files only because they match. Instead, compare each hit against a clean copy.
Step 2: Replace WordPress Core, Plugins, and Themes
This is the most reliable way to clean a hacked website, because it removes any injected code from the application files without needing to find every line.
Reinstall WordPress core
wp core download –force –skip-content
The –skip-content option keeps your wp-content folder, while overwriting wp-admin, wp-includes, and root files with clean versions. Then delete any unknown files in the root directory that are not part of WordPress and not part of your own configuration.
Reinstall plugins and themes
For each plugin and theme, delete the folder and install a fresh copy from the official repository or the vendor:
wp plugin install pluginname –force
wp theme install themename –force
Delete plugins and themes you do not use. Inactive ones can still be attacked. If a plugin is abandoned or no longer listed, replace it with a maintained alternative.
Warning about nulled software: Pirated “nulled” themes and plugins are one of the most common sources of infection. They often contain hidden backdoors. Replace them with legitimate copies.
Step 3: Clean the Uploads Folder and Other Writable Directories
Delete any PHP files found in uploads. Check other writable folders, such as caches, temporary directories, and backup plugin folders, for unfamiliar scripts. Also inspect:
- Hidden files, such as names that begin with a dot, or that imitate system files
- Files with double extensions, for example image.jpg.php
- Unusual folders in the web root or inside plugin directories
Step 4: Check and Repair Key Configuration Files
wp-config.php
Open it and look for code that does not belong, especially long encoded strings at the top or bottom of the file, or include statements that point to unfamiliar files. Compare it with the standard layout. You will replace the authentication keys later.
.htaccess (Apache) and server rules
Attackers frequently add redirect rules to .htaccess. Compare yours with the default WordPress rules, and remove anything you do not recognize. On Nginx servers, review the site configuration for injected rules. Also check parent directories, because a malicious .htaccess in a parent folder can affect your site.
index.php files and mu-plugins
Check that index.php in the root and in wp-content is the standard version. Inspect the wp-content/mu-plugins folder, which loads automatically and is a favorite hiding place for backdoors. Also review wp-content/drop-ins such as advanced-cache.php, which attackers sometimes abuse.
Step 5: Clean the Database
Malware does not live only in files. Spam links, hidden scripts, and rogue accounts can sit in the database.
Review users
wp user list –role=administrator
Delete any administrator you do not recognize. Also review other roles, since attackers sometimes create low-profile accounts they can promote later.
Search for injected scripts
Search posts, options, and widget content for <script, <iframe, and eval(:
wp db query “SELECT ID, post_title FROM wp_posts WHERE post_content LIKE ‘%<script%’ OR post_content LIKE ‘%<iframe%'”
Adjust the table prefix if yours is not wp_. Also check the wp_options table for suspicious entries, especially in siteurl, home, active_plugins, and any large encoded values.
Check scheduled tasks
Malware often schedules itself to return after cleanup. Run wp cron event list and delete any event you do not recognize.
If your database is badly damaged, restoring a clean backup from before the infection may be faster, as long as you are sure of the date the compromise began.
Step 6: Remove Backdoors and Check the Server
Backdoors are hidden files or code that let the attacker return even after you clean the visible infection. Skipping this step is the most common reason a site is reinfected within days.
On the server, check:
- Other websites in the same hosting account or under the same system user. If one site was infected, others may carry the same backdoor.
- Cron jobs for the web user and root: crontab -l and the files in /etc/cron.*
- SSH authorized keys in ~/.ssh/authorized_keys for users you do not recognize
- Unknown system users or processes running as the web server user
- Unexpected outbound connections from the server
- Hidden PHP files in temporary directories such as /tmp
If you find signs of compromise outside WordPress, such as unknown SSH keys or modified system files, treat the entire server as compromised. In that case the safest course is to rebuild the server from a clean image and restore only verified data. Our Linux server hardening checklist explains how to secure the rebuilt system.
Step 7: Change Every Credential and Security Key
Assume that all passwords are known to the attacker. Change:
- WordPress administrator and other user passwords
- Database password (and update wp-config.php)
- FTP, SFTP, and SSH passwords and keys
- Hosting control panel and domain registrar passwords
- API keys for payment gateways, email services, and other integrations
Then generate new WordPress security keys and salts from the official generator and replace the old ones in wp-config.php. This logs out every user and invalidates stolen session cookies.
Enable two-factor authentication for all administrators.
Step 8: Update Everything and Fix the Entry Point
Cleaning without fixing the cause invites reinfection. Common entry points include:
- Outdated plugins or themes with known vulnerabilities
- Nulled or abandoned software
- Weak or reused passwords, especially on admin and FTP accounts
- Compromised accounts on your computer or at your host
- Unpatched server software, such as an old PHP version
- Insecure file permissions that let any process write to your code
Update WordPress, every plugin and theme, and the server’s PHP version. Review your access logs around the time of the first infection for suspicious requests, such as POST requests to unusual PHP files. If you cannot identify the cause, ask a professional for a forensic review.
Step 9: Handle Google Warnings and Blacklists
If search engines or browsers flagged your site, cleaning is not enough. You must request a review.
- Open Google Search Console and go to the Security issues report.
- Confirm the problems are fixed, and select the option to request a review.
- Remove spam pages, or make sure they return a 404 or 410 status.
- Check your server IP and domain on common email and malware blacklists, and request delisting if necessary.
- Resubmit your sitemap.
Reviews usually take a few days. Explain clearly what you cleaned and what you changed to prevent a repeat.
Step 10: Harden WordPress Security Going Forward
A clean site is only temporary unless you strengthen it.
Inside WordPress
- Keep core, plugins, and themes updated, and enable automatic updates for security releases.
- Use only trusted, actively maintained plugins, and delete unused ones.
- Limit login attempts and add two-factor authentication.
- Use a unique administrator username, and avoid “admin.”
- Disable file editing in the dashboard by adding define(‘DISALLOW_FILE_EDIT’, true); to wp-config.php.
- Disable XML-RPC if you do not need it.
On the server
- Use secure file permissions, typically 755 for directories and 644 for files, with wp-config.php more restricted, for example 600 or 640.
- Block PHP execution in the uploads directory using a web server rule.
- Run each site under its own system user so one infection cannot spread to others.
- Keep PHP and server software updated.
- Install a web application firewall to block known attacks before they reach WordPress.
- Use fail2ban and a firewall to limit brute-force attempts.
Backups and monitoring
- Keep automated, off-server backups and test restores regularly.
- Enable file integrity monitoring and alerts for new admin users.
- Schedule weekly malware scans and review logs.
- Monitor uptime and Search Console for early warnings.
When to Call a Professional
Consider expert help if the infection returns after cleanup, if the server itself appears compromised, if you handle payment or personal data, or if you are not comfortable at the command line. Choose a provider that also identifies the cause and gives you a report.
Read More : Free SSL vs Paid SSL Certificates: Is There Any Real Difference?
Conclusion
A hacked WordPress site is stressful, but it is a solvable problem. The reliable path is to contain the damage, back up the evidence, scan carefully, replace core and plugin files with clean copies, remove backdoors and rogue users, rotate every credential, and then find and fix the way the attacker got in. Finish by requesting a review from search engines and hardening the site and server.
Prevention is far cheaper than cleanup. Keep software updated, limit what you install, run each site in isolation, and keep backups that you have actually tested. Do those things, and the next malware scare will be a minor inconvenience instead of a crisis.
