The most common story I hear from site owners who’ve been hacked more than once goes like this. The site was compromised, someone cleaned it, the spam pages disappeared, and everything looked fine. Then a week or a month later, the same problem came back. The cleanup removed the symptoms, but not the way in. Somewhere on the server, a small piece of code was still waiting, giving the attacker a private door back into the site. Knowing where WordPress backdoors hide is what turns a temporary cleanup into a permanent one.
That piece of code is a backdoor. WordPress backdoors are rarely dramatic. They’re often a few lines long, disguised to look like legitimate files and placed where nobody looks. Finding them is the difference between a cleanup that lasts and one that doesn’t. This article walks through where attackers typically hide them and practical ways to track them down.
What a backdoor is
A backdoor is any mechanism that lets an attacker regain access without going through the original vulnerability. If the original entry point was an outdated plugin, the attacker knows you’ll eventually update it. So, soon after getting in, they plant something else that doesn’t depend on that plugin.
Common forms include:
- A PHP file that executes whatever code is sent to it in a request
- A hidden administrator account
- Code injected into a legitimate file that runs on every page load
- A scheduled task that recreates malware if it’s deleted
- A database entry that a theme or plugin evaluates as code
- Modified server configuration that loads a malicious file
Many hacked sites contain several backdoors of different kinds. Attackers plant more than one precisely because they know cleanups often miss some.
Place 1: Fake or modified plugins
A favourite trick is creating a new folder in wp-content/plugins with a convincing name, such as wp-security-helper or cache-optimizer, containing a single PHP file. Sometimes it’s activated and visible in the plugins list. Often it’s hidden using code that removes it from the list.
Other times, attackers add a file inside a legitimate plugin folder, where it blends in with dozens of real files.
- Compare every installed plugin with a fresh copy from WordPress.org. WP-CLI can verify checksums for plugins hosted there:
- Look for plugin folders you don’t recognise, even if they don’t appear in the admin list.
- For premium plugins, which WP-CLI can’t verify, delete them and reinstall fresh copies from the vendor.
Reinstalling every plugin from a trusted source is often faster and more reliable than inspecting each one.
Place 2: Must-use plugins
The wp-content/mu-plugins folder loads every PHP file inside it automatically, on every request, without needing activation. Must-use plugins also appear in a separate, rarely visited tab of the plugins screen. That makes the folder an ideal hiding place.
Check it on every cleanup. Many sites don’t use mu-plugins at all, so any file there deserves scrutiny. Managed hosts do add their own mu-plugins, so learn what your host’s files look like.
Place 3: The uploads folder
The wp-content/uploads folder should contain images, documents and media. It should almost never contain PHP files. Yet it’s one of the most common places for backdoors, because file upload vulnerabilities drop files there, and many people never look.
Find PHP files in uploads:
A handful of plugins legitimately create PHP files in uploads, for example some caching, backup and form plugins that place an index.php to prevent directory listing. Inspect each result, but treat anything unexpected as malicious.
Once clean, prevent PHP execution in uploads at the server level. On Nginx:
On Apache, a .htaccess file in uploads with a rule denying PHP files does the same.
Place 4: Core files
Attackers sometimes modify WordPress core files, such as wp-includes/load.php, wp-settings.php or files in wp-admin, adding a line that includes their code. Others add new files to core folders with names like wp-tmp.php or class-wp-cache-handler.php that sound plausible.
WP-CLI can compare core files with official checksums:
It reports modified files and files that shouldn’t exist. The simplest fix is to replace core entirely:
That replaces wp-admin and wp-includes without touching wp-content.
Place 5: wp-config.php and the site root
The wp-config.php file is loaded on every request, so a single injected line there runs everywhere. Look for:
- include or require statements pointing to unfamiliar files
- Long encoded strings
- Code above the opening comment block or below the final require_once
Also check the site root for extra files. A clean WordPress root contains a predictable set of files: index.php, wp-config.php, the wp- prefixed core files, license.txt, readme.html, xmlrpc.php and the three folders. Anything else, like a file called wp-confg.php, about.php or a random string, needs investigating.
Check .htaccess and any .user.ini or php.ini files too. Attackers use directives like auto_prepend_file to load a malicious file before every PHP script, which is one of the stealthiest backdoors because no WordPress file is changed at all.
| <code>grep -rn "auto_prepend_file | auto_append_file" –include=".user.ini" –include="php.ini" –include=".htaccess" .</code> |
|---|
Place 6: Themes
Themes, including inactive ones, are another common target. The functions.php file is loaded whenever the theme is active, and attackers inject code into it. Inactive themes can still contain standalone backdoor files that can be accessed directly by URL.
Delete every theme you don’t use. Reinstall the active theme from a clean source if possible. For custom themes, compare with your version control repository, which is one of the strongest arguments for keeping custom code in Git.
Place 7: The database
Not every backdoor is a file. Attackers also use the database:
- Hidden administrator accounts. List administrators and question every one:
Also check the wp_usermeta table directly for users with administrator capabilities who don’t appear in the normal list, as some malware hides users from the admin screen.
- Malicious options. Some backdoors store code in the wp_options table and use a small loader file to execute it. Search for suspicious content:
Expect some false positives from legitimate plugins, and investigate each match.
- Injected scripts in posts and widgets. Search post content and widget options for script tags pointing to unfamiliar domains.
Place 8: Scheduled tasks
A clever backdoor reinstalls itself. Attackers add WordPress cron events that recreate malicious files, or server cron jobs that download fresh malware every hour.
List WordPress scheduled events:
Look for hooks with random names or names that don’t match any installed plugin. On the server, check the crontab for the site’s user:
An unfamiliar cron job that runs curl or wget against an external URL is a strong sign of persistence.
Recognising malicious code
Backdoor code tends to share some characteristics:
- Functions like eval, assert, create_function, preg_replace with the e modifier, or system and shell_exec
- Heavy use of base64_decode, gzinflate, str_rot13 or chains of them
- Variables used as function names, such as $f($x)
- Very long single lines of seemingly random characters
- Reading code from $_POST, $_GET, $_COOKIE or $_REQUEST and executing it
A useful search across the codebase:
| <code>grep -rnE "eval( | base64_decode( | gzinflate( | str_rot13( | assert(" wp-content –include=*.php | less</code> |
|---|
Many legitimate plugins use base64_decode for normal reasons, so treat matches as leads, not proof. The combination of obfuscation and execution of request data is the real red flag.
Also look at file modification times. Files modified around the time of the compromise, especially in folders that rarely change, deserve a closer look:
| <code>find . -name "*.php" -mtime -30 -printf "%TY-%Tm-%Td %pn" | sort</code> |
|---|
Attackers sometimes fake modification dates, so this is helpful but not conclusive.
The cleanest approach: rebuild, don’t hunt
Hunting for every backdoor in an infected installation is slow and uncertain. The most reliable cleanup replaces everything that can be replaced:
- Download fresh WordPress core.
- Reinstall every plugin and theme from trusted sources.
- Copy only the uploads folder from the old site, after removing any PHP or executable files from it.
- Recreate wp-config.php from scratch with new salts and database credentials.
- Review the database for malicious users, options and content.
- Check server-level configuration and cron jobs.
Then close the original entry point, rotate every credential and set up file integrity monitoring so any new unexpected file triggers an alert. Done this way, WordPress backdoors have nowhere left to hide.
Monitoring after the cleanup
Once the site is clean, the following weeks are when you find out whether anything was missed. Set up file integrity monitoring that alerts you when PHP files are added or changed outside normal updates. Watch the administrator list and the activity log. Keep an eye on outgoing traffic and email volume, because some backdoors are used quietly for spam rather than visible defacement. If something reappears, compare its location and timing with your notes from the cleanup, because that usually points straight at the persistence mechanism that survived.
Frequently asked questions
Can a security plugin find all backdoors?
Good scanners find many, especially known malware signatures. Custom or heavily obfuscated backdoors can slip through, and database or server-level persistence is often missed. Combine scanning with the manual checks above.
Why did my site get reinfected after cleaning?
Usually because a backdoor was missed, the original vulnerability wasn’t fixed or credentials weren’t changed. All three need attention.
Is it safe to restore from a backup?
Only if the backup predates the compromise. Attackers often wait days or weeks before acting, so recent backups may already contain backdoors.
Should I tell my host?
Yes. On shared hosting especially, the host can check for server-level issues and other affected accounts.




