You cleaned it. You scanned it. The security plugin said all clear. Then, three days later, the spam pages are back, visitors are being redirected to a pharmacy site, or Google is flagging your site again. If that sounds familiar, here is the uncomfortable truth: your WordPress site almost certainly was not hacked twice. It was hacked once, and the first cleanup missed a layer.
As a WordPress and Shopify developer who has cleaned up hacked sites for store owners, I have seen the same pattern over and over. The visible malware is the least important part of the infection. The parts that bring it back are the ones you cannot see: a small loader file, a payload hidden in the database, a scheduled task, or an administrator account somebody created quietly. Delete the files you can see and the loader writes them back within minutes. Delete the loader but leave the account, and the attacker walks back in by hand.
This guide gives you the cleanup order that actually stops reinfection. The order matters more than any single step, because each layer of the infection restores the others. Follow it in sequence and you fix the problem once. Skip around and you will be cleaning the same site again next week.
Why Your WordPress Site Keeps Getting Hacked
A reinfection almost never means the attacker broke in again. It means the cleanup missed a layer. Most WordPress malware has three parts working together:
- A loader. A small piece of code that runs on every request and rebuilds the malware. It often hides in
wp-content/mu-plugins, where files load before normal plugins and cannot be switched off from the dashboard, or in a file tucked insidewp-includeswhere it blends in with thousands of core files. - A stored payload. The actual malicious code, kept somewhere file scanners do not look. Autoloaded database options are a favorite hiding place, because they run on every page load and survive a full file cleanup.
- A way back in. An administrator account the attacker created, an application password, a stolen hosting credential, or a scheduled task that re-downloads the payload every hour.
What you see, the fake CAPTCHA, the redirect, the skimmer on the checkout, is the payload. It is the least important part to remove, and it is the only part most cleanups target. That is why the site keeps getting hacked.
The entry point is usually unglamorous. In rough order of frequency: an outdated plugin with a known exploit, a nulled or pirated theme that shipped with a backdoor, a weak or reused administrator password, stolen SFTP or hosting credentials, or a neighboring site on the same shared hosting account. Finding which one it was is part of the cleanup, not an optional extra.
The Cleanup Order That Stops Reinfection
Here is the full order, before the detail:
- Contain the site and preserve the evidence.
- Find the entry point.
- Replace core, plugins, and themes with clean copies.
- Hunt the database and the hidden persistence mechanisms.
- Rotate every credential and reset the salts.
- Harden the site, then ask Google to lift any warning.
Do not start at step 3. Cleaning files before you know how the attacker got in is how sites get reinfected on a schedule.
Step 1: Contain the Site and Preserve the Evidence
The first hour is for documenting, not deleting. Before you change anything, take a full copy of the files and database exactly as they are, even though they are infected. That snapshot is evidence: it lets you work out how the attacker got in, and it is your rollback if a cleanup step goes wrong. Store it somewhere separate from your normal backups.
Next, stop the site from infecting visitors. Put it into maintenance mode or restrict access to your own IP address at the hosting or CDN level. A maintenance plugin alone is not enough if the malware serves content through direct script URLs, so an IP restriction or a hosting level block is the safer choice while you work.
Then write down what you are seeing: the date and time you noticed it, the symptoms (redirects, spam pages, Google warning, host suspension), and any URLs affected. Check Google Search Console for the Security Issues report and for owners you do not recognize. If your site takes payments, note the discovery time, because data protection rules start a clock from the moment you become aware of a breach.
Do not restore a backup yet. If the backdoor predates the backup, and it often does by weeks, you will restore the compromise along with the clean-looking site and conclude the malware is unkillable.
Step 2: Find the Entry Point Before You Clean
Cleaning without diagnosis is why reinfection is so common. Four checks find the cause in most cases:
- Check plugin and theme versions against known vulnerabilities. Outdated plugins are by far the leading cause. List every plugin and theme, note the version, and check whether a security fix was released after your installed version. A plugin that has not been updated in two years is a suspect, not a feature.
- Read the access logs around the first sign of trouble. Find the earliest modified file, then search the logs for the request that touched it. That request is usually the entry point. Download at least 30 days of logs before they rotate away.
- Look for files that do not belong. Any PHP file inside
wp-content/uploadsis malicious, because nothing should ever execute there. Recently modified files inwp-includesorwp-adminare also strong signals. The fastest signal is modification time, because attackers rarely bother to reset it. - Check for added administrator accounts and scheduled tasks. Attackers commonly create a user to return through, and register a scheduled task that reinstalls the payload after you clean it. A site that reinfects on a regular cycle almost always has a scheduled task nobody looked for.
If you have WP-CLI access, wp core verify-checksums and wp plugin verify-checksums --all compare your installed files against the official releases and list every file that has been altered. That one command often does in seconds what an hour of manual inspection cannot.
Step 3: Replace Core, Plugins, and Themes (Do Not Scrub Them)
Cleaning an infected file by hand means being confident you spotted every insertion. Replacing it means being confident about nothing at all, which is a better position.
Download a fresh copy of WordPress from wordpress.org and replace the wp-admin and wp-includes folders with the same version your site runs. Do this over SFTP or your host file manager, not through the dashboard reinstall option, because the dashboard reinstall overwrites the files WordPress ships and leaves files the attacker added in place.
Delete every plugin and theme folder and reinstall each one from its official source, the WordPress.org directory or the vendor website. Do not just update them. A compromised plugin update mechanism is a classic reinfection vector, and an update only replaces files the plugin ships. Remove any plugin or theme you do not use. Deactivated is not gone: deactivated plugins still sit on the server and can still be exploited.
Keep wp-content/uploads and wp-config.php, but inspect both. Uploads should contain media only, never PHP. And wp-config.php is one of the files attackers modify most, so read it line by line against a clean copy.
Step 4: Hunt the Database and the Hidden Persistence
This is the step most cleanups skip, and it is the step that decides whether the malware comes back. Cleaning files while leaving a database backdoor means the infection returns on the next page load.
Work through this checklist:
- Unknown administrators. Go to Users and delete any administrator you do not recognize, reassigning their content to a real user first. Also check for existing customer or subscriber accounts quietly given the administrator role. The most durable way back in is not code at all, it is an account.
- Application passwords and API keys. Revoke every application password and regenerate any API keys stored in the site configuration. An attacker with a key does not need your password.
- Autoloaded options. Search the options table for anything you do not recognize, especially long encoded strings. Autoloaded options run on every page load, which makes them the ideal place to hide a reinfection routine. It survives file cleanup and rewrites the payload the moment you finish.
- Must-use plugins. Open
wp-content/mu-pluginsand account for every file in it. Must-use plugins load on every request and cannot be disabled from wp-admin, so a loader planted here is invisible to most site owners. - Scheduled tasks. List every WP-Cron event and every server cron job. A loader that registers a scheduled task can re-download or rewrite the malware every hour, long after you deleted the files it wrote. Plugins such as WP Crontrol list the scheduled tasks; delete anything you cannot explain.
- Stray files in core folders. A PHP file placed in
wp-includes/imagesorwp-admin/includeslooks at home among thousands of core files. Reinstalling WordPress does not remove it, because installers overwrite the files they ship, and hacks usually add new ones. Compare the folder contents against a fresh download.
A note on scanners: a security plugin runs inside the site it is protecting, so malware that controls the site can control what the plugin sees. Rename the plugin folder and it is off, hide a plugin from the list and it is not there, keep the payload in the database and there is no file to match. Use a scanner as a second opinion, and pair it with a remote scan such as Sucuri SiteCheck, which checks from the outside. A clean remote scan is not the final word either, but two independent checks beat one.
Step 5: Rotate Every Credential and Reset the Salts
Once the site is clean, assume everything was read. Rotate all of it: WordPress administrator passwords, the hosting control panel password, SFTP and SSH credentials, the database password (and update wp-config.php to match), and any API keys stored in the site.
Then generate fresh authentication salts and keys in wp-config.php (fresh ones are available at the WordPress.org secret key generator). This forces every logged-in session to expire, including the attacker’s. Changing one password achieves nothing if the attacker still holds a valid session cookie or a second administrator account.
If you found the entry point was a stolen hosting credential, change the recovery email password too, and check the hosting account for unknown FTP users, SSH keys, or subdomains the attacker may have added.
Step 6: Harden the Site So It Stays Clean
Cleanup without hardening is a countdown to the next incident. These are the changes that actually move the needle:
- Update everything, then keep it updated. Core, plugins, and themes, on a schedule you actually follow. Enable auto-updates for minor core releases and for plugins you trust. Most hacked sites were running a version with a published fix.
- Use strong, unique passwords and two-factor authentication on every administrator account. Limit login attempts and consider restricting wp-admin access to specific IP addresses if your team is small.
- Run a firewall. A web application firewall, either a plugin such as Wordfence or a service such as Cloudflare, blocks known exploit attempts before they reach WordPress. Keep it in its optimized mode and avoid logging settings that bloat your database.
- Remove what you do not use. Every unused plugin and theme is an entry point you are maintaining for free. Delete them, do not just deactivate them.
- Keep PHP current. An outdated PHP version is a vulnerability in itself. In late 2026 a critical PHP flaw was actively exploited in the wild, and the fix shipped in PHP 8.3.36. If your host still runs an older version, ask for the upgrade, because no plugin can patch the language underneath your site.
- Lock down file permissions and uploads. Directories should be 755 and files 644, and your server should never execute PHP from the uploads folder. Most hosts can disable PHP execution in uploads with a single rule.
- Back up properly this time. Automated daily backups stored off the server, with a retention window long enough to reach a backup from before any future compromise. Test a restore at least once, because a backup you have never restored is a hope, not a plan.
For a fuller treatment of the performance side of this, including plugin audits and database hygiene, see the WordPress speed optimization guide. A lean site is easier to secure and easier to clean, because there are fewer places for malware to hide.
When a Backup Helps and When It Hurts
Restoring a backup is the fastest route to a clean site, but only when three conditions are all true: you know the compromise date, you have a backup from before it, and you have identified and fixed the vulnerability. Without all three, a restore fails predictably, because you either restore the backdoor or leave the hole open for the next attack.
If you cannot prove the backup predates the infection, do the manual rebuild in steps 3 and 4 instead. It takes longer, but it is the only method that does not depend on a guess about when the attacker arrived.
Getting Google to Lift the Warning
If Google flagged your site, fixing the files is only half the job. Go to Google Search Console, open the Security Issues report, and confirm every listed issue is resolved. Then request a review. Google re-crawls the affected URLs and, if they are clean, lifts the warning, usually within a few days.
While you wait, check that your site is not still serving spam pages to search engines. A common trick is cloaking: the site looks clean to you and serves spam to Googlebot. Fetch a few affected URLs as Googlebot through the URL Inspection tool and read what it actually returns.
WooCommerce Stores Need Extra Checks
If the hacked site is a WooCommerce store, add two checks before you call it clean. First, inspect the checkout for a payment skimmer: malicious JavaScript that copies card details as customers type them. Skimmers hide in theme files, in the database, and in compromised plugins, and they are the reason a hacked store can become a legal problem, not just a technical one. Second, review recent orders and customer accounts for anything the attacker changed, including shipping addresses and account email addresses.
A hacked WooCommerce store is also a good moment to ask whether the platform still fits. If maintenance, plugin conflicts, and security patches are eating your time every month, many store owners find the move worth it. The WooCommerce to Shopify migration guide covers the full cost, timeline, and SEO checklist, and the WordPress vs Shopify comparison lays out when each platform is the better choice. And if the store is slow as well as compromised, the WooCommerce speed optimization guide covers the store-specific fixes, from HPOS to cart fragments.
When to Call a Developer
Most single-site hacks can be cleaned by following this order carefully. Call a developer when the infection keeps returning after a full ordered cleanup, when the site is a WooCommerce store handling live payments, when customer data may have been exposed, or when you cannot identify the entry point. A professional cleanup also includes a written diagnosis: the cause, the scope of the repair, and what was changed, which matters if you need to report the incident or claim on insurance.
If your site keeps getting hacked and you would rather have it fixed properly once, hire a developer who works with WordPress and WooCommerce every day. A clean rebuild, a hardened configuration, and a backup routine that actually works cost far less than a second or third cleanup, and far less than the sales a flagged site loses while it sits in Google’s warning list.
FAQs
Why does my WordPress site keep getting hacked after I clean it?
Because the cleanup missed a layer. The visible malware is only the payload. A loader in mu-plugins, a payload hidden in an autoloaded database option, a scheduled task, or an administrator account the attacker created will each bring the infection back after the files are cleaned. Work through the full order: contain, find the entry point, replace files, clean the database, rotate credentials, then harden.
How do I know if my WordPress site is hacked?
The clearest signs are a Google warning, your host suspending the site, spam pages appearing in search results, visitors being redirected to unrelated sites, unknown administrator accounts, and files modified at times when nobody was working on the site. A free remote scan such as Sucuri SiteCheck confirms known malware and blocklist status from the outside, though a clean result is not the final word.
Can I clean a hacked WordPress site myself?
Yes, if you are comfortable with SFTP and the database, and the site is a single install without payment data at risk. Follow the order in this guide and do not skip the database and credential steps. If the site takes payments, handles customer data, or reinfects after a full cleanup, get a developer involved.
Should I restore a backup or clean the site manually?
Restore a backup only if you know the compromise date, you have a backup from before it, and you have fixed the vulnerability. Otherwise restore the backdoor along with the site. If any of those three is uncertain, rebuild manually: replace core, plugins, and themes with clean copies, then hunt the database.
How long does it take Google to remove a hacked site warning?
After you request a review in Search Console, Google re-crawls the affected URLs and usually lifts the warning within a few days, provided the site is genuinely clean. If the warning returns, something is still on the site, usually a database backdoor or a cloaked spam page that only Googlebot sees.
Will a security plugin stop my site from being hacked again?
A firewall and scanner help, but they are not a substitute for updates, strong credentials, and removing unused plugins. A security plugin runs inside the site it protects, so malware that controls the site can control what the plugin sees. Hardening is the combination: updated software, two-factor authentication, a firewall, minimal plugins, current PHP, and real backups.