Ravindra BagaleCourses & study guides Track your progress

Guides

WordPress Site Hacked: How to Recover, Clean and Secure It Step by Step

If your WordPress site is hacked, work in this order: contain it (maintenance mode and a full backup for evidence), change every password (hosting, SFTP/SSH, database, all admins) and the salts in wp-config.php, remove unknown admin users, reinstall WordPress core, plugins and themes from clean copies, hunt for backdoors (especially PHP files in wp-content/uploads), then update everything, add 2FA, and ask Google to review the site. Restoring a backup alone is not enough if the hole they used stays open.

First 30 minutes

  1. Take a full backup of files + database (evidence, and so you lose nothing).
  2. Change hosting, SFTP/SSH and database passwords.
  3. In WordPress → Users, delete admins you do not know.
  4. Replace keys and salts in wp-config.php (from api.wordpress.org/secret-key/1.1/salt/).
  5. Update or remove every plugin and theme.

A live example first

A small clinic's WordPress site started sending mobile visitors from Google to a fake "you won a prize" page. Desktop visitors saw nothing wrong, which is a common trick.

  1. Contain: the admin turned on maintenance mode and downloaded a full backup with the host's tool.
  2. Users: WordPress → Users showed an admin wp-support-team created two days ago. Deleted (posts reassigned).
  3. Find PHP in uploads:
find wp-content/uploads -name "*.php"
wp-content/uploads/2026/09/cache-img.php

That file contained obfuscated code (eval(base64_decode(...))). Uploads should never contain PHP.

  1. Recently changed files:
find . -name "*.php" -mtime -7 -not -path "./wp-content/cache/*"

This showed an edited theme functions.php and a plugin folder wp-content/plugins/wp-cache-helper/ that nobody had installed.

  1. Cause: a slider plugin two years out of date with a known vulnerability.
  2. Fix: fresh core with wp core download --force --skip-content, clean plugin copies, removed the fake plugin and the slider, new salts, all passwords changed, 2FA added, Google review requested in Search Console.

Friends, the redirect was the symptom. The old plugin was the disease.

How does recovery work?

WordPress hack recovery Contain the site, rotate all credentials, remove fake admins and backdoors, reinstall clean code, then harden and request review. WordPress hack recovery Containbackup + offlinePasswordsall + saltsAdminsremove fakesClean codereinstallHardenupdate + 2FA you Cleaning is not enough. Close the hole they used to get in

Recover in order: contain, rotate passwords, remove fakes, reinstall clean, harden, then ask Google to review.

Attackers usually leave more than one way back in: a fake admin, a backdoor file, a changed theme, and stolen passwords. Recovery has to remove all of them and close the original hole, otherwise the site is re-hacked within days.

How do I recover step by step?

  1. Put the site in maintenance mode or take it offline.
  2. Take a full backup (files + database) and keep it separately for evidence.
  3. Change hosting control panel, SFTP/SSH, and database passwords; update wp-config.php with the new DB password.
  4. Replace the keys and salts in wp-config.php to log everyone out.
  5. Review all users; remove unknown admins; reset passwords for real ones.
  6. Reinstall WordPress core from WordPress.org (keep wp-config.php and wp-content).
  7. Delete and reinstall every plugin and theme from the official source. Remove any you do not use.
  8. Search wp-content/uploads and mu-plugins for PHP files and remove them.
  9. Check the database for strange admin users and injected <script> tags in posts and options.
  10. Or restore a backup from before the hack, then do steps 3–5 and update everything.
  11. Scan with a security plugin or an outside scanner.
  12. Request a review in Google Search Console if Google flagged the site.

Commands and checks by access type

Access Useful checks
WP-CLI (SSH) wp core verify-​checksums, wp plugin verify-​checksums --​all, wp user list --​role=​administrator
SSH / Linux find wp-​content/​uploads -​name "*.​php", find . -​mtime -​7 -​name "*.​php", grep -​rl "eval(base64_​decode" .
cPanel / hosting panel File Manager sorted by modified date, Malware scanner, raw access logs
Only wp-admin Users list, Plugins list, a security plugin scan
Database (phpMyAdmin) wp_users, wp_usermeta (capabilities), wp_options siteurl/home

wp core verify-checksums compares core files with official copies and lists any that were changed.

Harden after cleaning

Action Why
Auto-update plugins and themes Most hacks use known, already fixed bugs
Remove unused plugins/themes Less code to attack
Never use nulled (pirated) plugins They often come with backdoors
2FA for all admins Stops password-guessing and reuse
Unique strong passwords Stops credential stuffing
define('DISALLOW_​FILE_​EDIT', true); Blocks editing PHP from wp-admin
Block PHP in uploads Web server rule, so uploaded PHP cannot run
Off-site daily backups Fast clean restore
A web application firewall Blocks common attacks

Real example

In June 2024, the WordPress.org plugin team and the security firm Wordfence reported that several plugins on the official directory were changed by an attacker to include malicious code that created new admin accounts and sent the details to the attacker. This is why "check for unknown admins" is always an early step, and why plugin updates and monitoring matter even for trusted plugins.

Mistakes to avoid

  1. Only deleting the one bad file you found. There are usually more.
  2. Restoring a backup and leaving the old plugin. You will be hacked again.
  3. Keeping the old passwords. The attacker may already have them.

Summary table

Step Action
Contain Maintenance mode + full backup
Credentials Change all passwords + salts
Users Remove unknown admins
Code Reinstall core, plugins, themes cleanly
Backdoors PHP in uploads, mu-plugins, theme files
Harden Updates, 2FA, remove unused, firewall
Reputation Google Search Console review

Quick quiz: check what you learned

  1. What is the most common way WordPress sites get hacked?

    1. Outdated or bad plugins
    2. Too many blog posts
    3. Using the default theme
    4. Having a contact form
    Show answer

    A. Vulnerable and nulled plugins are the top cause.

  2. Where do PHP backdoors often hide?

    1. wp-content/uploads
    2. The robots.txt file
    3. Your CSS stylesheet
    4. The favicon image
    Show answer

    A. Uploads should hold media, not PHP files.

  3. Why replace salts in wp-config.php?

    1. To log out every session
    2. To speed up the site
    3. To change the site theme
    4. To move to a new host
    Show answer

    A. New salts invalidate existing login cookies.

  4. After cleaning, how do you clear the Google warning?

    1. Request a Search Console review
    2. Change the logo on every page
    3. Buy more ads on Google Search
    4. Rename the home page file
    Show answer

    A. Search Console lets you request a security review.

Frequently asked questions

How do I know my WordPress site is hacked?

Common signs: redirects to spam or scam sites, new admin users you did not create, Google "This site may be hacked" warnings, Japanese or pharma spam pages in search results, or your host suspending the site.

Should I just restore a backup?

A clean backup from before the hack is a great start, but you must also fix how the attacker got in (an old plugin, stolen password), or they come back.

How do attackers usually get in?

Most often through vulnerable or outdated plugins and themes, nulled (pirated) plugins, or weak or reused admin passwords.

Where do backdoors hide?

In PHP files inside wp-content/uploads, fake plugin folders, edited theme files like functions.php, mu-plugins, and sometimes in the database.

How do I remove the Google warning?

After cleaning, verify the site in Google Search Console, check the Security issues report, and request a review.

Do security plugins help?

Yes, for scanning and a firewall, but they do not replace updates, strong passwords, 2FA and backups.