Home / Guides

Server guide

Hacked WordPress site: cleanup steps with WP-CLI

Cleaning a hacked WordPress site is not only deleting a bad file. You must find what changed, remove it and close the way in, or it comes back.

2 min readUpdated November 2026 by the RootManage teamWorks on Ubuntu, Debian, AlmaLinux and Rocky unless noted

The short answer

Take a backup, put the site in maintenance, verify core and plugin files, look for new admins and PHP files in uploads, reinstall clean copies, change every password and key, and update everything.

Contain it and keep a copy

  • Take a full backup of files and database before you change anything. It is evidence, and it is a way back.
  • Put the site in maintenance mode, or block the public with a password in front of it.
  • Change your hosting, SFTP and database passwords from a clean computer.

Check WordPress core and plugin files

terminal
cd /path/to/site
wp core verify-checksums
wp plugin verify-checksums --all

These compare your files with the official copies. Anything listed as changed or unknown needs attention. Themes have no checksum list, so inspect them yourself.

Look for what does not belong

terminal
wp user list --role=administrator
find wp-content/uploads -name "*.php"
find . -name "*.php" -mtime -7 -not -path "./wp-content/cache/*"

PHP files inside uploads, files changed in the last week that you did not change, and administrator users you do not know are the usual signs. Also check .htaccess, wp-config.php and the index.php files.

Replace, do not patch

terminal
wp core download --force --skip-content
wp plugin install <name> --force
wp config shuffle-salts

Reinstall core and every plugin from the official source, and delete plugins and themes you do not use. Shuffling salts logs everyone out. Remove unknown users and reset the remaining passwords.

Check the database and the server

  • Look for injected scripts in posts, widgets and options (search for <script, eval( and base64_decode).
  • Check cron jobs and scheduled tasks for new entries.
  • On a shared server, check the other sites in the same account. One infected site often infects its neighbours.

Close the way in

Find how it happened: an outdated plugin, a weak password, a stolen login or a nulled theme. Update everything, turn on two-step login for admins and keep backups off the server. If you cannot find the cause, the attack is likely to return. A fixed-price cleanup includes finding the cause.

Questions people ask

Can I just restore a backup?

Only if the backup is from before the hack, and you also close the hole. Otherwise the site is hacked again the same way.

Will Google remove the warning?

After the site is clean, ask for a review in Search Console. It takes some days.

How do I know it is fully clean?

You cannot be sure from the outside. Compare files with official copies, check users and scheduled jobs, and watch the logs for some days.

Want a person to look at it?

Tell us what you see. We reply with what we think is wrong and what it would take to fix it.