WordPress Site Hacked? A Calm Step-by-Step Recovery Plan
What to do, in order, when a WordPress site is compromised: confirm it, contain it, keep the evidence, clean or restore, change every secret, find the way in and clear the warnings.

Finding your WordPress site hacked is unpleasant, and the first instinct is to start deleting whatever looks wrong. Resist it. Sites get reinfected for two reasons: the cleanup removed the visible damage and left the way in, or the evidence that would have shown the way in was deleted in the first ten minutes.
This plan puts the work in an order that avoids both mistakes: confirm, contain, copy, clean or restore, lock out, find the cause, then clear the warnings. Do not rush it, because rushing is how backdoors get missed.
Is the WordPress site hacked, or only broken?
A blank page after an update, an expired certificate or a full disk can look alarming and have nothing to do with security. These signs are different:
- visitors are redirected to another site, often only on phones or only when they arrive from a search engine
- search results for your domain show pages you never wrote, usually in another language or selling something unrelated
- an administrator account exists that nobody on the team created
- the browser shows a red "Deceptive site ahead" page, or Google Search Console lists a security issue
- the host has suspended the account or reports spam being sent from it
- there are PHP files in
wp-content/uploads, or.htaccessandindex.phphave changed and nobody changed them
Check the site logged out, in a private window and by clicking through from a search result, because malicious code often hides from logged-in administrators. Write down what you see and when you saw it.
Contain the site, then copy everything before you clean
Containment means visitors stop receiving whatever was injected and the attacker's files stop being reachable while you work. A maintenance-mode plugin does not achieve that, because WordPress and the infected code still run on every request. Use the hosting panel to password-protect the site's directory or restrict it to your IP address, or ask the host to do it.
From a computer you trust, change the hosting panel and SFTP passwords straight away. Then take a full copy of the site as it is now:
- every file, including hidden ones such as
.htaccess - a database export
- the web server access and error logs, which hosts rotate after days or weeks, so download them today
Label the archive as infected and keep it off the server. It is your evidence for working out how the attacker got in and your safety net if the cleanup breaks something.
Restore or clean: choose the route
| Restore a clean backup | Clean the live site | |
|---|---|---|
| Fits when | A backup exists from before the infection and you can date the infection | No trustworthy backup, or too much has changed since the last clean one |
| What you lose | Everything created since that backup: orders, sign-ups, posts, form entries | Nothing, if the cleanup is complete |
| Main risk | Restoring a copy that was already infected | Missing a backdoor |
To date the infection, look for the oldest suspicious file by modification time, the registration date of any unknown user and the first odd requests in the access log. A restore also puts the vulnerable plugin or the stolen password back in place, so it is never the last step.
On a store or a learning site, the usual middle route is to replace all code from clean sources and keep the live database, then inspect the database separately. That keeps orders and progress records intact. Planning for this is part of a WordPress backup strategy you can restore from.
Clean in a fixed order
- Replace WordPress core. Delete the
wp-adminandwp-includesfolders completely and upload fresh copies of the same version from WordPress.org. Overwriting is not enough, because attackers add new files and an overwrite leaves those behind. - Replace every plugin and theme. Delete each folder and install a fresh copy from WordPress.org or the vendor. Custom code should come from version control or the developer's last delivery. If the only copy is on the infected server, it needs a line-by-line review.
- Inspect what cannot be replaced. Compare
wp-config.phpwithwp-config-sample.phpand look for extraincludelines or code you do not recognize. Check every.htaccessfile, thewp-content/mu-pluginsfolder and any PHP files sitting directly inwp-content. The uploads folder should contain no PHP at all. - Check the database. Review the user list, the site address settings, scheduled tasks and any post or option containing a script you did not add.
- Update everything and delete plugins and themes you do not use.
- Scan again with a malware scanner, then view the site logged out and from a search result.
With WP-CLI, these commands do much of the checking:
wp core verify-checksums
wp plugin verify-checksums --all --skip-plugins --skip-themes
find wp-content/uploads -type f -name "*.php"
wp user list --role=administrator --fields=ID,user_login,user_registered --skip-plugins --skip-themes
wp cron event list --skip-plugins --skip-themes
The first command runs without loading WordPress and reports core files that differ from the official release or should not exist. The plugin check only covers plugins hosted on WordPress.org. The --skip-plugins --skip-themes flags matter on an infected site, because most WP-CLI commands load plugin and theme code, and you do not want to execute it. The official WordPress guide for hacked sites lists further places to look.
Change every secret the attacker could have read
Anyone who could run PHP on the server could read wp-config.php and the whole database. Assume they did. Change all of the following once the site is clean, and not before, because a backdoor that survives the cleanup simply reads the new values.
- Salts. Replace the eight keys in
wp-config.php(fromAUTH_KEYtoNONCE_SALT) with fresh values, or runwp config shuffle-salts. This ends every logged-in session, including the attacker's. - User passwords. Reset them for every administrator and editor at a minimum, and remove accounts you cannot account for.
- Application passwords. Revoke them on each profile and reissue only the ones in use.
- The database password. Change it at the host and update
DB_PASSWORDinwp-config.php. - Hosting, SFTP and SSH credentials, again, now that the site is clean.
- API keys stored in the site's settings: the payment gateway, the email service, the CRM, the backup storage.
Find how they got in
Open the evidence copy. Take the modification time of the oldest malicious file and read the access log for the minutes before it. You are looking for the request that created it: a POST to a file inside a plugin folder, a burst of requests to admin-ajax.php, or a login to wp-login.php answered with a redirect, which means the password was correct.
Then compare the plugin and theme versions in the evidence copy against a public vulnerability database, and check whether any plugin came from somewhere other than its author. Look at the other sites in the same hosting account too. One infected site can write to its neighbors and reinfect the one you have just cleaned.
Sometimes the logs are gone and the cause stays unknown. Then treat every likely cause as real: update everything, remove what is not needed, turn on two-factor login and watch file changes closely for the next month.
Ask Google and your host to lift the warnings
In Google Search Console, open the Security issues report. It lists what Google found, with sample URLs. When the site is clean, select "Request Review" and describe what the problem was and what you did about it. The Search Console help page for this report sets out what a good request contains. Do not ask early, because a request sent before the site is clean slows down the next one. Reviews take from several days to a few weeks.
If the host suspended the account, send them the same summary. If customer accounts, orders or other personal data may have been read, you may have a legal duty to notify people or a regulator. Speak to your own counsel quickly, since those deadlines can be short.
When a cleanup needs a developer
A small site with a clean backup, standard plugins and intact logs is within reach of a careful owner following the steps above. Hand it over when the site takes payments or holds customer records, when it runs custom code that exists only on the infected server, when several sites share the account, or when the infection has already come back once.
Afterwards, the priority is making sure there is no repeat. Our WordPress security checklist covers the settings to put in place, and a WordPress maintenance plan keeps updates, backups and monitoring from slipping again. If the hosting itself was the weak point, moving the site to a better-isolated host belongs on the list.
Frequently asked questions
Why does the malware keep coming back after I remove it?
Something was left behind. The usual causes are a backdoor file that the cleanup missed, a rogue administrator account or scheduled task in the database, a vulnerable plugin that was never updated, a password that was never changed, or another infected site in the same hosting account.
Should I move to a new host after a hack?
Moving alone fixes nothing, because the infected files and the vulnerable plugin move with you. Clean first. A move makes sense afterwards if the host cannot give you access logs, runs an unsupported PHP version or does not isolate the sites in an account from each other.
Can a security plugin clean a hacked site by itself?
A scanner is good at finding known malware and changed core files, and some can remove what they find. None of them can tell you how the attacker got in, and automated removal sometimes misses a custom backdoor, so treat the scan as one step of the plan above.
Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.
