How to find the compromised WordPress plugin that caused the hack
You trace the infection by comparing file modification timestamps against your last known-good backup and cross-referencing the malware scanner's file list with the plugin and theme directories, then remove the source file and its database hooks. Most recovery guides stop at "run a scanner and restore." That leaves the backdoor in place. The manual method below shows you exactly which file to delete and why, using only the tools already on your server.
Key takeaways
- Free scanners miss novel backdoors because they only match known malware signatures, leaving the source file in place.
- Generate a list of plugin and theme files sorted by modification time to identify files changed after your last clean backup.
- Cross-reference the scanner's flagged files with the timestamp shortlist to isolate the specific plugin or theme directory containing the injection logic.
- Search the database for the plugin's hooks and remove those entries before deleting the plugin folder to prevent orphaned rows from re-triggering the redirect.
- Delete the compromised plugin folder entirely and restore the site from a known-good backup, then check the uploads directory for secondary payloads.
Why the scanner alone misses the backdoor
Free scanners work by matching file contents against a database of known malware signatures. If the backdoor uses a novel obfuscation technique or a freshly written payload, the scanner has no signature to match against, and the file passes clean. This is why reinfection happens: the scanner reports "no threats found," you restore the site, and the hidden backdoor re-establishes the redirect within hours. The goal of this method is not to delete the redirect script the malware injected into your homepage. That script is the symptom. The goal is to find the source file inside a plugin or theme directory that created and maintains that redirect. Without locating the source, every cleanup is temporary.
Map the infection window with file timestamps
Log into your server via SSH or your host's file manager. Navigate to wp-content/plugins and wp-content/themes. Generate a list of every file in those directories sorted by modification time. On a Linux server, run find wp-content/plugins -type f -printf '%T@ %p\n' | sort -n and the same command for wp-content/themes. Now pull up your last clean backup and note the timestamp of the most recent file in that backup. Any plugin or theme file whose modification time falls after that backup timestamp is a suspect. You do not need to know which file is malicious yet. You only need the shortlist. This step narrows hundreds of files down to the handful that changed during the hack window.
Cross-reference scanner output with the directory map
Export the full flagged-file list from your malware scanner, even if it reports only a few hits. Open that list side by side with your timestamp shortlist. Match each flagged file path to the plugin or theme folder it lives in. If a flagged file sits inside wp-content/plugins/woocommerce-payments/, that plugin is the compromised component. If the scanner found nothing but your timestamp list shows three files modified during the hack window, those three files are your suspects. Open each one in a text editor. Look for base64-encoded strings, eval() calls, or file_put_contents writing to wp-config.php or theme files. The file that contains the injection logic is your source.
Check the database for the plugin's hooks
Before deleting the plugin folder, search the database for traces it left behind. Connect via phpMyAdmin or the command line. Run SELECT * FROM wp_options WHERE option_value LIKE '%plugin-slug%' and the same query against wp_posts. Look for injected JavaScript, redirect URLs, or serialized data tied to that plugin's rows. Remove those database entries before deleting the file. If you delete the plugin first, the orphaned database rows can re-trigger the redirect on the next page load. For a full walkthrough of database cleanup, see How to clean a hacked WordPress database.

Remove the source and restore from a clean backup
Delete the compromised plugin or theme folder entirely. Do not just deactivate it. Then restore the site from your last known-good snapshot. The safest and easiest way to restore WordPress is by using a backup plugin like Duplicator [1]. After the restore, run a fresh file listing on wp-content and confirm no residual files from the removed plugin remain. Check wp-content/uploads as well, since some backdoors drop secondary payloads there. If your backup is older than the hack window, you will need to re-apply legitimate changes made after that backup by hand.
Harden against reinfection with version checks
Update every remaining plugin and theme to the latest version. For premium plugins, confirm the developer hooks into the WordPress plugins_api so version checks work [2]. If a plugin has no active developer, no recent update, and no changelog, remove it. An unpatched plugin is the most common entry point for the next infection. For a full hardening checklist, see How to harden WordPress against reinfection after a hack.
Understand the vulnerability landscape you are defending against
In 2025, 11,334 new WordPress vulnerabilities were disclosed, representing a 42% year-over-year increase [3]. Wordfence recorded 319 vulnerabilities in 222 WordPress plugins during the week of September 21–27, 2026 [4]. This volume means an unpatched plugin is a likely entry point, making source identification critical. If you are paying a freelancer or agency to maintain the site, understand what that maintenance actually covers. See the Freelance Web Design Hidden Costs Guide for what to expect in a maintenance contract. For the full step-by-step recovery process, the WordPress Hack Recovery Checklist walks through every stage from isolation to Google review request.
Frequently asked questions
Why does the site get reinfected after running a free malware scanner?
If the backdoor uses a novel obfuscation technique, the scanner has no signature to match, reports no threats, and the hidden backdoor re-establishes the redirect.
What command lists plugin files by modification time on a Linux server?
Run find wp-content/plugins -type f -printf '%T@ %p\n' | sort -n to generate a list of every file in the plugins directory sorted by modification time.
What code patterns indicate a file contains injection logic?
The file containing this logic is the source of the infection.
Why must database entries be removed before deleting the plugin folder?
If you delete the plugin first, orphaned database rows containing injected JavaScript or redirect URLs can re-trigger the redirect on the next page load.
Sources
Related on this site
- How to get your hosting account unsuspended after a WordPress hack
- Website hack downtime cost calculator – free calculator
- WordPress Hack Recovery Checklist – the full guide
- WordPress hack recovery guide – every article on this topic
This article was drafted with AI assistance and checked before publication.
Free calculator: Website hack downtime cost calculator
The full guide: WordPress Hack Recovery Checklist
