In this guide
Your three options
| Option | Works well when… | Risks |
|---|---|---|
| Clean the current site | The infection is identifiable and the site is otherwise worth keeping (most cases) | A missed backdoor means reinfection; needs a methodical process |
| Restore a backup | You have an off-site backup from before the infection, and you know when it started | Recent backups are often infected too; you lose changes since the backup; the hole stays open |
| Rebuild from scratch | The site is small or simple, or so badly damaged that cleaning isn’t worth it | Most work; infected content or uploads can be carried over; the entry point may be repeated |
When restoring a backup works
A restore is a good option if all of these are true:
- the backup is stored off your server (so the attacker couldn’t change it);
- you know roughly when the infection started, and the backup is older;
- you can accept losing everything since that date: orders, posts, comments, users;
- you fix the entry point right after restoring, by updating plugins and changing passwords.
Restore into a staging copy first and scan it before going live. If you’re unsure when the infection started, assume the backup is infected.
When rebuilding makes sense
Rebuilding is worth considering if the site is small, or it was already overdue for a redesign, or the infection is so widespread that cleaning would cost more than starting over. If you rebuild:
- Start on clean ground. Fresh WordPress, freshly downloaded plugins and themes, new database, new passwords, ideally a clean hosting account.
- Move content, not code. Never copy over old plugins, themes or
wp-config.php. - Check the content you import. Search the export for
<script,<iframe,eval(and links to domains you don’t know. - Copy only real media from uploads. Images, PDFs and documents only; never
.php,.jsor unknown extensions. Check that image files are actually images. - Don’t repeat the mistake. Find out how the old site was hacked, or the new one will be too.
Why cleaning is usually the best choice
For most sites, a proper cleanup is faster and cheaper than a rebuild, keeps all your content and recent changes, and, crucially, includes finding out how the attacker got in. That’s the part that stops it happening again, whichever option you choose.
My step-by-step guide to fixing a hacked WordPress site walks through a full cleanup.
From my cleanup work: I regularly see sites that were “rebuilt from scratch” after a hack and infected again within a month. The new site used the same outdated page builder that let the attacker in the first time, and the owner had copied the whole uploads folder over, including two backdoors disguised as image files. The rebuild cost weeks; finding those two things would have taken an hour.