WordPress Homepage Defaced: Recover Step by Step
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.
- 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.
- 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 - Copy the database. Run
mysqldump -u DB_USER -p DB_NAME > ~/evidence-db.sql(your database name and user are inwp-config.php). - 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.
- 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.
| Situation | Best choice | Why |
|---|---|---|
| You have a backup from before the defacement and you know roughly when it happened | Restore | Fast, and removes unknown changes |
| Only the homepage or one theme file changed, and you can verify everything else | Repair in place | Less lost content, but only if checks come back clean |
| Orders, comments or posts were added after the last clean backup | Restore 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 links | The database can hold injected admin users, malicious options, rogue scheduled tasks and script-injected posts, so never merge it wholesale |
| No clean backup exists | Repair in place, with a fresh WordPress install of core files | Replace everything you can, then audit the rest |
| You cannot tell when the attacker first got in | Restore the oldest backup you trust | A 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
.htaccessfor unfamiliar redirect rules, and look inwp-content/mu-plugins(code there loads automatically and does not show in the plugin list). The--skip-pluginsflag 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.
- Change every credential. WordPress admins, hosting panel, SFTP/FTP, SSH, the database password (update
wp-config.phpto match), and the email account tied to the admin. - Replace the security keys and salts (random strings in
wp-config.phpthat protect login sessions) with fresh ones fromhttps://api.wordpress.org/secret-key/1.1/salt/. This logs out everyone, including the attacker's sessions. - Turn on two-factor login for every admin. A free plugin such as WP 2FA does this.
- Stop in-dashboard file editing. Add
define( 'DISALLOW_FILE_EDIT', true );towp-config.php, as suggested in the WordPress hardening guide. - Fix file permissions. The same guide suggests folders at
755and files at644, withwp-config.phptighter. - Remove the unused. Delete inactive plugins, themes and old admin accounts.
- Turn on automatic updates for minor core releases and for plugins you trust.
- 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.
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