WordPress site hacked: how to fix it, step by step
How to clean a hacked WordPress site: save the current state, replace core and plugin files with official copies, remove PHP from uploads and unknown admins, change passwords and keys, ask Google for a review.
To fix a hacked WordPress site you save the current state, replace WordPress, plugin and theme files with clean copies from official sources, remove what the intruder added (PHP files in uploads, unknown accounts, code in the database), then change every password and key and close the hole they came in through. Deleting the one file a scanner flagged almost never ends it, because intruders leave themselves more than one way back.
Below is the order a developer works in. Some steps you can do yourself in the WordPress dashboard and your hosting panel. Others need access to the files (FTP or the hosting file manager) and the database. If you are not sure yet that the site was hacked, start with the signs of a hacked website.
Step 1: copy what is there now
Before you change anything, copy the files and the database in their current, infected state and keep the copy off the server. Ask your host for the server logs of the last few weeks. Both are needed to find out how someone got in. Without them you clean up the effects and the cause stays.
If the site sends visitors to scams, put up a maintenance page while you work. A day offline is better than customers sent to a fake prize draw.
Step 2: compare WordPress files with the official release
WordPress.org publishes a checksum for every file of every release. A developer with SSH access checks the files with WP-CLI:
wp core verify-checksums
wp plugin verify-checksums --all
The first lists core files that differ from the official ones and files that are not part of the release. The second does the same for plugins from the WordPress.org directory. Paid plugins and themes cannot be checked this way. Compare them with a fresh download from the vendor.
The safest approach is not to repair changed files but to replace them whole: delete wp-admin and wp-includes and upload them from the same WordPress version, then reinstall plugins and the theme from official sources. Leave wp-config.php and wp-content/uploads in place, they hold your settings and media. You review those two by hand in the next steps.
Do not reinstall "nulled" plugins or themes from unofficial sites. They are one of the common ways malicious code gets onto a site in the first place.
Step 3: PHP files in uploads and places nobody looks
wp-content/uploads is for images and documents. A PHP file in it is almost always a backdoor that lets someone control the server from a browser. A developer finds them with:
find wp-content/uploads -name "*.php"
In the hosting file manager you can also sort by modification date and look at files changed in the last few weeks. Then check:
wp-content/mu-plugins: plugins in this folder always run and do not appear in the normal plugin list,.htaccessin the root folder and in subfolders, for redirects nobody added,wp-config.php, for code added at the very top or bottom,- cron jobs in the hosting panel, for commands that download malicious code again every hour.
Step 4: accounts, database, passwords and keys
In the dashboard open Users and filter by Administrator. A developer runs wp user list --role=administrator as well, because malicious code can hide an account from the dashboard list. Delete accounts nobody recognises and attribute their content to someone on your team.
In the database, injected code usually sits in post and page content (added scripts and links) and in the options table. Check that both addresses in Settings > General are yours, and search posts for <script where nobody put one.
Then passwords, all at once, from a computer you trust: WordPress administrators, hosting panel, FTP, database (the new one also goes into wp-config.php) and mailboxes on the domain. Finally new security keys in wp-config.php, with wp config shuffle-salts or from the official WordPress.org generator. New keys log everyone out, including an intruder with a saved session.
Step 5: close the way in
Update WordPress, every plugin and the theme. Delete plugins you do not use rather than just deactivating them. If the logs or file dates show how they got in, for example through an old version of a particular plugin, write it down. You will need it for the review request to Google. If the site is hacked again a few days later, the redirect hack guide lists the places that are most often missed.
Step 6: Google and browsers
Look up the site in Google Safe Browsing site status and, if you have Search Console, open the Security issues report. If Google lists something, request a review there once the site is clean. How to word it and how long it takes is in Google says your site is dangerous.
What nobody can promise
After a break-in, nobody honest will tell you the site is certainly clean. You can check the known places, compare files with the originals and watch the site over the following weeks. If you have a backup from before the break-in, restoring it and updating everything is usually more reliable than cleaning by hand, as long as the backup really predates the first infection.
The free Ensomedia Security plugin compares WordPress, plugin and theme files with the official checksums, looks for PHP files and web shells in uploads, and flags accounts that have administrator rights without the Administrator role. It does not clean the site for you: it shows where the problem is, and it removes code injected into a theme, uploads, posts or options only after you approve each change, with a backup and a way to undo it.
Common questions
Is a security plugin enough?
A plugin helps find changed files and unknown accounts. It cannot tell you how someone got in, and it does not change your hosting or database passwords. Without those steps the hack usually comes back.
Do I have to restore a backup?
No, but if you have one from before the break-in it is the fastest route. Infections often sit on a site for weeks, so yesterday's backup may already be infected.
How long does it take?
For a small site with a backup, a few hours of work. Cleaning by hand without a backup takes longer, and Google removing a warning adds anything from a day to several weeks.
If you would rather not do it yourself
Not sure it is malware? Run the free website check. It works from the outside, with no password and no account, and shows among other things whether the domain is on threat lists and whether the home page code contains suspicious redirects.
If the site is hacked and you want someone to do the work, order a hacked site fix. We remove malicious code, unknown accounts and redirects, update what let the intruder in and tell you what happened. From $99. We reply within 1 business day with the scope and the price, and you pay only after you accept.