Key points
- Don’t start deleting things in a panic: snapshot the infected site, change your hosting credentials, then investigate.
- Reliable clean-up means reinstalling core and plugins from official sources, checking the database and user accounts, then rotating every key and password.
- Until you find and close the way in, the site will be hacked again. It’s the step people skip most often.
It often starts with a customer email: “your website sent me to a casino”. Or Google replaces your listing with a red warning, or your host suspends the account because it’s sending thousands of spam emails. Whatever the trigger, the instinct is the same: delete the odd-looking files, restore a backup, move on. When sites come to us after that kind of quick fix, the infection is usually back within days, because the backdoor or the original vulnerability is still there. This guide walks through the method we use on our own incident work: what to do first, which commands to run, what to check, and when it’s time to call in help. The commands use WP-CLI, which most hosts provide with SSH access; without it, every step can still be done over SFTP and phpMyAdmin, just more slowly.
How to tell your site has been hacked (it isn’t always obvious)
Modern attacks are designed to stay hidden. A defaced site gets fixed quickly; a site quietly working for the attacker earns them money for months. These are the signs we come across most:
- Selective redirects: the site looks fine when you’re logged in, but sends visitors arriving from Google, or only mobile visitors, or each visitor only once a day, somewhere else. That’s deliberate, so the owner never notices.
- Pages you never created in Google: searching
site:yourdomain.comturns up Japanese-language pages, counterfeit shops or pharmacy spam. - A security warning in Chrome (“Dangerous site”) or in Google Search Console under Security Issues.
- An administrator account nobody recognises, often named to look legitimate (
admin2,wp-support). - A warning from your host: mass outgoing email, unusual CPU usage, files flagged by their malware scanner.
- Innocent-looking files in odd places: a
cache.phpinside the uploads folder, awp-something.phpat the root that isn’t part of WordPress.
Any one of these is enough to treat the site as compromised. Slowness on its own isn’t: a slow site far more often has a caching or plugin problem than malware.
The first few hours: contain it without destroying the evidence
Order matters more than speed. Deleting everything straight away destroys exactly what you need to work out how the attacker got in. Here’s what we do, in this order:
- Snapshot the infected state (files and database) and store it off the server. You’ll need it for the investigation, and as a fallback if the clean-up breaks something.
- Put the site into maintenance mode so visitors are no longer exposed, without taking it down entirely.
- Change every credential that doesn’t live in WordPress: your hosting control panel, FTP and SFTP accounts, and the database password (then update
wp-config.php). If the attacker has those, any clean-up is pointless. - Tell your host, especially on shared hosting. They often keep fuller logs than you can see and can check whether other sites on the account are affected.
- Write down times and symptoms: that log will help you date the intrusion later.
# 1. Copy the infected state BEFORE touching anything (evidence + rollback)
cd /home/account/www
tar czf ~/incident-$(date +%F)-files.tar.gz .
wp db export ~/incident-$(date +%F)-db.sql
# 2. Put the site in maintenance mode while you investigate
wp maintenance-mode activate
One precaution people forget: if several sites share a hosting account, treat them all as compromised. A malicious script dropped in one site can usually read and write the others’ files, because they all run as the same system user. We once cleaned a site thoroughly only to see it reinfected the next day from an old staging copy sitting forgotten in a subfolder.
Find what was changed: files, database, accounts
The goal is a complete list of what the attacker added or modified. Start with files. WP-CLI can compare every core file, and every plugin from the official directory, against the versions published on wordpress.org. Any mismatch deserves a look.
# Core and plugin files that differ from the official releases
wp core verify-checksums
wp plugin verify-checksums --all
# PHP files changed in the last 15 days (cache excluded)
find . -name "*.php" -mtime -15 -not -path "./wp-content/cache/*" -printf "%TY-%Tm-%Td %pn" | sort
# PHP inside the media folder: there should never be any
find wp-content/uploads -type f ( -name "*.php" -o -name "*.phtml" -o -name "*.phar" )
# Must-use plugins, loaded without showing in the usual plugin list
ls -la wp-content/mu-plugins/
# Typical obfuscation patterns
grep -rlE "eval(|base64_decode(|gzinflate(|str_rot13(|assert($_" wp-content/ --include=*.php
How to read the results, from experience:
verify-checksumsdoesn’t cover premium plugins or themes. Compare those with a fresh copy downloaded from the vendor.- Modification dates can be faked: attackers sometimes copy the timestamp of a neighbouring file. Dates help you build a timeline; they don’t prove a file is clean.
- The pattern search throws up false positives, since some legitimate plugins use
base64_decode. Open each flagged file. Malicious code is usually unreadable, crammed onto one very long line, or full of nonsense variable names. - A modified
.htaccesson its own can cause the redirects. Check the one at the root and look for others in subfolders.
Then move on to the database and user accounts. Some infections leave no files at all: a script injected into a post, a widget or an option is enough to redirect visitors.
# Administrator accounts: do you recognise every one?
wp user list --role=administrator --fields=ID,user_login,user_email,user_registered
# Scripts injected into content and options
wp db search "<script" --all-tables --stats
wp db query "SELECT option_name FROM wp_options WHERE option_value LIKE '%eval(%' OR option_value LIKE '%<iframe%'"
# Unknown scheduled tasks (a backdoor can reinstall itself)
wp cron event list --fields=hook,next_run_relative,recurrence
Swap wp_ for your table prefix if it’s different (wp config get table_prefix). Before deleting an unknown admin, note when it was created: that date is a valuable marker for the rest of the investigation. Check editor accounts too. They can’t install plugins, but they can inject links into content.
Clean up: reinstall, don’t repair
You have two options: restore a clean backup, or clean the site in place. Restoring is quicker if three things are true: you know when the infection started, you have a backup from before that date, and you can live with losing whatever was published since (orders, posts, sign-ups). In practice, the intrusion usually predates the first symptoms by a long way, and the “clean” backup isn’t. So we usually clean in place, following one rule: you don’t fix a file, you replace it with an official copy.
# Reinstall core from wordpress.org (wp-content and wp-config.php are left alone)
wp core download --force --skip-content --version=$(wp core version)
# Reinstall every plugin from the official directory, at its latest version
wp plugin install $(wp plugin list --field=name --status=active) --force
# New security keys: every logged-in session is invalidated
wp config shuffle-salts
# New password for every account (a reset link is emailed)
wp user reset-password $(wp user list --field=user_login)
wp maintenance-mode deactivate
Then, by hand:
- The theme: reinstall it from its source (the official directory, the vendor’s site, or your agency’s Git repository for a custom theme) and reapply your customisations, reviewing each one.
- Premium plugins: download fresh copies from your vendor account. Any “nulled” plugin, meaning a paid plugin obtained free from a third-party site, has to go. It’s one of the most common infection sources we see, because the backdoor ships with the plugin.
- The uploads folder: delete any PHP file in it, then block script execution there (see below).
- Unused plugins: a deactivated plugin is still on the server and still exploitable if it has a vulnerability. Remove anything you don’t use.
- The database: strip out the injected scripts you found earlier, delete unknown accounts and suspicious scheduled tasks.
Rotating keys (shuffle-salts) and passwords comes last, once the backdoors are gone. Changing passwords on a site that’s still infected just hands them to the attacker. Don’t forget API keys stored in the site (payment gateway, email service, external storage): if wp-config.php or the database may have been read, regenerate them.
Finish with an end-to-end check. Re-run the checks from the previous step, which should now come back clean, then test the site from a phone in a private window, arriving via a Google result, to reproduce the conditions selective redirects rely on.
Find the way in, or it all starts again
This is the step quick clean-ups leave out. The site was hacked because there was an opening; if it’s still there, bots will find it again, often within days. The causes we find most often, roughly in order: a plugin or theme with a known, unpatched vulnerability; a weak or reused admin password; a nulled plugin; another vulnerable site on the same hosting account; and, more rarely, a compromised computer that leaked FTP credentials.
Server access logs often settle the question. Start from the creation date of the first suspicious file or account and look at what happened just before:
# POST requests to PHP files, outside normal WordPress traffic
grep '"POST ' access.log | grep -vE 'wp-cron.php|admin-ajax.php|wp-login.php'
| awk '{print $7}' | sort | uniq -c | sort -rn | head -20
# Who called the suspicious file, and since when?
grep 'wp-content/uploads/2026/10/cache.php' access.log | head
A burst of POST requests to one particular plugin’s file, just before the first malicious file appeared, almost always points to the vulnerability used. Then check whether that plugin recently shipped a security fix: the public WordPress vulnerability databases (WPScan, Patchstack, Wordfence Intelligence) list the affected versions. If the flaw is known and there’s no fix, replace the plugin.
Successful logins to wp-login.php from an unfamiliar address, with no exploit beforehand, point to a compromised password instead. Many hosts only keep logs for a few days, which is one more reason to move quickly and ask for a copy at the very start.
After the clean-up: Google, your customers and your obligations
If Google flagged the site, the warning won’t vanish overnight on its own. Once the site is clean, go to Security Issues in Search Console and click Request Review, describing exactly what you did: files removed, plugins replaced, vulnerability fixed. A vague “the site has been cleaned” is less likely to succeed. Review times vary, from a few days to a few weeks.
Spam pages the attacker created need to drop out of the index. Make them return 410 (“Gone”) rather than redirecting them, and use Search Console’s Removals tool to hide the worst ones quickly. Also check the attacker hasn’t added themselves as an owner of your Search Console property or submitted their own sitemap. We’ve seen both.
If the site holds personal data (customer accounts, form submissions, orders) and it may have been accessed, data protection law probably applies. Under the GDPR, a breach must be reported to the supervisory authority within 72 hours of becoming aware of it, unless it’s unlikely to put people at risk, and the people affected must be told if the risk is high. Other jurisdictions have their own rules. Don’t leave this until the clean-up is over: write down what you know as you go.
Finally, if your domain was sending spam, check the email blocklists and request delisting once the problem is fixed. Otherwise your legitimate emails can keep landing in junk folders for weeks.
Preventing a repeat: the protections that actually matter
A cleaned site with no hardening is just waiting for the next attack. On our maintenance plans, this is what we put in place every time, roughly in order of impact:
- Regular, monitored updates for plugins, theme and core, tested on a copy of the site first for major releases. This is by far the most effective measure.
- Fewer plugins: every plugin adds attack surface, and any that’s no longer maintained by its author gets replaced.
- Two-factor authentication for every admin and editor account, with unique passwords from a password manager.
- No executable scripts in the uploads folder, and no file editor in the dashboard:
# wp-content/uploads/.htaccess (Apache) : no executable scripts among the media
<FilesMatch ".(php|phtml|phar)$">
Require all denied
</FilesMatch>
# Nginx equivalent, inside the server block
location ~* ^/wp-content/uploads/.*.(php|phtml|phar)$ {
deny all;
}
// wp-config.php
define( 'DISALLOW_FILE_EDIT', true ); // no file editor in the dashboard
define( 'FORCE_SSL_ADMIN', true );
- Automatic off-site backups, kept for several weeks, and actually tested: a backup you’ve never restored is only a hope.
- Monitoring: alerts on file changes, new admin accounts, and Search Console security reports.
- Hosting that isolates each site under its own system user, so one compromised site can’t infect the others.
None of this makes a site invulnerable. Together, though, these measures move a site from “easy target for bots” to “too much effort for too little reward”, and that’s enough to keep out the vast majority of automated attacks WordPress sites face every day.
FAQ
A security plugin says it has cleaned the site. Is that enough?
Rarely. These tools are good at spotting known malicious files, but they often miss custom backdoors, database injections and the original vulnerability. Treat their report as a starting point, then follow the method: reinstall from official sources, check accounts, find the way in.
Do we need to rebuild the whole site after a hack?
No, unless it was already running on an abandoned theme and unmaintained plugins. In that case the hack is usually a symptom of a deeper problem, and rebuilding on a sound foundation can cost less than repeated clean-ups.
Everything was up to date. How did we still get hacked?
The usual explanations are a compromised password (reused on another service that was breached), another vulnerable site on the same hosting, or a flaw exploited before its patch was released. That’s exactly why two-factor authentication and site isolation matter.
Has your WordPress site been hacked, or do you want to make sure it doesn’t happen? We clean compromised sites, track down the vulnerability, then look after maintenance and monitoring. Get in touch for help.



