WordPress Homepage Defaced: Recover Step by Step

By Bug Circuit Security Team
WordPress Homepage Defaced: Recover Step by Step

Is your own website affected? Check it free in 2 minutes.

Passive outside check only. Nothing is attacked, no signup.

If your WordPress homepage now says "hacked by" something, work in this order: take a copy of the site as evidence, restore from a clean backup (or repair in place only if you can prove what changed), find how the attacker got in, and harden the site before it goes live again.

This is for owners of WordPress sites whose homepage was replaced, for example with a "hacked by Mr Green" page. You will get a calm triage order, copy-pasteable checks, and a clear way to decide between restoring and repairing. If you want the broader picture first, see our page on what to do when your website is hacked.

What a defacement actually tells you

A defacement is when someone changes what visitors see, usually the homepage, to show a message or a name. If you searched for "wordpress hacked by mr green", you have seen this pattern: a dark page, a handle, sometimes music or a greeting.

The name in the message tells you very little. Many people reuse the same defacement pages, and a name is not a fingerprint of how they got in. Treat the message as a symptom, not a diagnosis.

The real concern is what else changed. Someone who could edit your homepage could often also add an admin user, plant a hidden backdoor (a file that lets them back in later), or read your database. Plan for that, without panic.

Step 1: Contain the site and take a copy for evidence

Do this before you fix anything. Once you clean up, the clues are gone.

  1. Put up a maintenance page or take the site offline. Your host can often do this at the server level. This stops visitors seeing the message and limits further damage.
  2. Copy all the files. Download the whole WordPress folder over SFTP (secure file transfer), or make an archive on the server: tar -czf ~/evidence-files.tar.gz /path/to/site
  3. Copy the database. Run mysqldump -u DB_USER -p DB_NAME > ~/evidence-db.sql (your database name and user are in wp-config.php).
  4. Save the logs. Ask your host for the web server access and error logs covering the days before the defacement. They show which URLs the attacker called.
  5. Store the copy somewhere private. Keep it off the public web folder and away from the live site.

The copy is for investigation only. Never restore from it or run it on a public server.

Step 2: Decide whether to restore or repair in place

For most small sites, restoring is safer and faster. Repairing in place means you must find every changed file yourself, and a single missed backdoor lets the attacker return.

SituationBest choiceWhy
You have a backup from before the defacement and you know roughly when it happenedRestoreFast, and removes unknown changes
Only the homepage or one theme file changed, and you can verify everything elseRepair in placeLess lost content, but only if checks come back clean
Orders, comments or posts were added after the last clean backupRestore files and database from the clean backup. Then re-add only the new posts, comments or orders from the evidence copy by hand, and check each one for injected code or linksThe database can hold injected admin users, malicious options, rogue scheduled tasks and script-injected posts, so never merge it wholesale
No clean backup existsRepair in place, with a fresh WordPress install of core filesReplace everything you can, then audit the rest
You cannot tell when the attacker first got inRestore the oldest backup you trustA backup taken after the break-in may contain the backdoor

The last row matters. Attackers often get in days or weeks before they change the homepage. Pick the backup from before the earliest suspicious sign you can find, such as an unknown admin user or a file with an odd modified date.

Step 3: Restore (or repair) in a safe place first

Do not restore straight onto the live, public site if you can avoid it. If your host offers a staging copy, use it. Otherwise keep the maintenance page up while you work.

If you are restoring:

  • Restore both files and database from the same date.
  • Immediately update WordPress core, every plugin and every theme. The old hole is probably still open in the restored version.
  • Delete plugins and themes you do not use. Inactive code can still be attacked.

If you are repairing in place, use these checks:

Run every command below from the site folder, as the site's normal user, not as root. Every WP-CLI command (WP-CLI is the WordPress command-line tool, often available on managed hosts) loads WordPress, including any backdoored plugin, theme or mu-plugin, so a check could run the attacker's code. Add --skip-plugins --skip-themes to each wp command, as shown below.

  • Also check .htaccess for unfamiliar redirect rules, and look in wp-content/mu-plugins (code there loads automatically and does not show in the plugin list). The --skip-plugins flag does not skip mu-plugins, so inspect that folder by hand. Then run these two commands to confirm both values point to your domain:
wp option get siteurl --skip-plugins --skip-themes
wp option get home --skip-plugins --skip-themes

Next, look for files that should not exist. Do this before you reinstall core, because reinstalling overwrites changed core files, which would hide them from these checks and make every core file look recently modified:

find wp-content/uploads -name "*.php"
find . -name "*.php" -mtime -14
grep -rlF -e "eval(base64_decode" -e "gzinflate(base64_decode" wp-content

The uploads folder should hold images and documents, not PHP code, so any .php file there is a strong warning sign. The other two commands list recently changed PHP files and a few common signs of obfuscation (code deliberately scrambled to hide what it does). A match is a lead to examine, not proof, and a clean result does not prove the site is clean. Premium themes sometimes use these functions legitimately, so check before you delete.

Then list your admin users and remove any you do not recognise:

wp user list --role=administrator --skip-plugins --skip-themes

Now let WordPress compare your files against the official originals:

wp core verify-checksums --skip-plugins --skip-themes
wp plugin verify-checksums --all --skip-plugins --skip-themes

Note that wp plugin verify-checksums --all only works for plugins from WordPress.org. Premium and custom plugins are not covered, so review those by hand.

Finally, clean up core. Delete any file that verify-checksums reports as "should not exist", or remove the wp-admin and wp-includes folders. Then run:

wp core download --force --skip-content

This step matters because the command only overwrites files and never deletes extra ones, so a planted PHP file in wp-admin or wp-includes would survive without the delete. Your content in wp-content is left alone.

If any of this feels beyond you, that is normal. It is the main reason restoring is the better default.

Step 4: Find the entry point

If you skip this step, you are likely to be defaced again. Common ways in for WordPress sites include:

  • An outdated or vulnerable plugin or theme. Check the plugin names against the National Vulnerability Database and the plugin's changelog. The OWASP Top 10 (2021) lists vulnerable and outdated components as a top web risk.
  • A stolen or guessed password. This covers WordPress admins, hosting, FTP and the database.
  • Nulled (pirated) plugins or themes. These often ship with backdoors built in.
  • Another site on the same hosting account. An old, forgotten site can be the door to the current one.
  • A weak host or shared server. Ask your host whether the server itself was affected.

Use your logs to narrow it down. Look for the first time an unfamiliar IP address requested an odd file, such as /wp-content/plugins/some-plugin/upload.php, or sent a POST request (a request that sends data to a page, such as a form submission) to a page that should not accept one. Then check what changed on the server around that time. Even a rough answer ("it was probably this plugin, last updated 14 months ago") tells you what to fix first.

Step 5: Harden before you go live again

Do these before you remove the maintenance page.

  1. Change every credential. WordPress admins, hosting panel, SFTP/FTP, SSH, the database password (update wp-config.php to match), and the email account tied to the admin.
  2. Replace the security keys and salts (random strings in wp-config.php that protect login sessions) with fresh ones from https://api.wordpress.org/secret-key/1.1/salt/. This logs out everyone, including the attacker's sessions.
  3. Turn on two-factor login for every admin. A free plugin such as WP 2FA does this.
  4. Stop in-dashboard file editing. Add define( 'DISALLOW_FILE_EDIT', true ); to wp-config.php, as suggested in the WordPress hardening guide.
  5. Fix file permissions. The same guide suggests folders at 755 and files at 644, with wp-config.php tighter.
  6. Remove the unused. Delete inactive plugins, themes and old admin accounts.
  7. Turn on automatic updates for minor core releases and for plugins you trust.
  8. Set up backups that are stored off the server and that you have tested by restoring one.

Then run a free passive check of your domain to catch easy misses.

Step 6: Go live and watch for relapse

Remove the maintenance page, then check the homepage in a private browser window. Search Google for site:yourdomain.com and look for strange pages, because some attackers add spam pages as well as defacing the homepage.

If your hosting provider or Google flagged the site, request a review once you are clean. Keep an eye on the logs and your admin user list for the next few weeks. Remember that nothing makes a site 100% safe. The goal is to close the hole you found and make the next attempt harder.

Where a human review helps

Automated scanners can spot known bad files, but they cannot tell you why your site was open in the first place. A person can look at your login flow, your plugins' behaviour and your configuration, and see how the pieces fit. If you are curious about the difference, read our comparison of manual and automated testing.

Key takeaways

  • Copy the files, the database and the logs first. Cleanup destroys evidence.
  • Restore from a backup taken before the earliest sign of compromise. Repair in place only when you can verify every file.
  • Update everything on the restored site before it goes public, or the same hole will be used again.
  • Change every password, replace the salts, add two-factor login and remove unused plugins and users.
  • The name in the defacement message does not tell you how they got in. Your logs and your plugin list do.

What to do next

Once the site is back, the honest question is whether the hole is really closed. Bug Circuit's Essential plan is $49 one-time for 1 website and 3 manual audits within a month. A real security engineer tests your site by hand and writes a full report with every issue, its severity and how to fix it. It is a small-site audit, not an incident-response cleanup or a compliance certification. Fixing is separate: we quote it per issue and you pay only if you agree. Reports usually arrive within about 5 business days after the site is verified and the Authorization to Test is signed. See the plans and prices if you want details, or start with the free check above.

Want certainty, not guesswork?

A real human security engineer audits your whole site by hand and sends a full report: every issue, its severity, and the exact fix. From $49, with a 14-day money-back guarantee.

See pricing

Frequently asked questions

How do I fix a WordPress site that says hacked by Mr Green?
Take the site offline and copy the files, database and logs first. Then restore from a backup made before the break-in, update WordPress, plugins and themes, change all passwords and replace the security keys in wp-config.php. Find and close the entry point before you go live, or the site can be defaced again.
What does wordpress hacked by mr green mean?
It means someone changed your homepage to show a defacement message with that name. The name is just text on the page and does not tell you how they got in. Often the cause is an outdated plugin or a weak or stolen password, and other files or admin users may have been changed too.
Should I restore from a backup or repair a hacked WordPress site in place?
Restoring is usually safer, because you do not have to find every changed file. Repair in place only if you can verify every file, user and setting, for example when only one file changed or no clean backup exists. Pick a backup from before the earliest sign of compromise, since a later one may contain a backdoor.
How do I find out how my WordPress site was hacked?
Start with your web server access logs and look for odd requests to plugin files or unexpected POST requests around the time of the change. Check which plugins and themes were outdated, which admin users are new and which files were recently modified. If the evidence is unclear, a manual security review can test for the weak spots.
Will restoring a backup remove the hacker?
Only if the backup is clean and you close the original hole. If the backup contains a backdoor, or the vulnerable plugin is still installed, the attacker can come back. Update everything and change all credentials right after restoring.

Keep reading

See what attackers see, for free

Run the free passive check on your website. No login, no impact on your site, results in seconds.

Ready for the full manual audit? See pricing

Published by Bug Circuit. Written with AI assistance and reviewed for accuracy before publishing.