WordPress Security ServicesMalware Removal
Recovery Options

Hacked WordPress Site: Should You Rebuild, Restore a Backup, or Clean It?

When a WordPress site is hacked, the first instinct is often to wipe it and start again, or to restore last week's backup. Sometimes that's the right call. Often it brings the infection straight back. Here's how to decide between cleaning, restoring and rebuilding, and how to move your content safely if you rebuild.

Sergey By Sergey, WordPress security specialist Updated 2 min read
In this guide
  1. Your three options
  2. When restoring a backup works
  3. When rebuilding makes sense
  4. Why cleaning is usually the best choice

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:

  1. Start on clean ground. Fresh WordPress, freshly downloaded plugins and themes, new database, new passwords, ideally a clean hosting account.
  2. Move content, not code. Never copy over old plugins, themes or wp-config.php.
  3. Check the content you import. Search the export for <script, <iframe, eval( and links to domains you don’t know.
  4. Copy only real media from uploads. Images, PDFs and documents only; never .php, .js or unknown extensions. Check that image files are actually images.
  5. 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.

Sergey, WordPress Security Specialist
About the author
Sergey, WordPress Security Specialist

10 years in WordPress security and incident investigation, and more than 200 websites cleaned of malware. Top Rated on Upwork with a 100% Job Success score. More about me

Frequently Asked Questions

If I restore a backup, will the malware be gone?

Only if the backup is from before the infection started, and even then the hole the attacker used is still there. Infections often start weeks before anyone notices, so recent backups may already contain the backdoor.

If I export my posts and import them into a fresh WordPress, can the malware come with them?

Yes. A WordPress export includes post content, so scripts injected into posts come along. Uploads can contain PHP files disguised as media. Check the content before importing, and only copy real media files from uploads.

Is rebuilding from scratch the safest option?

It can be, but it's also the most expensive and it doesn't tell you how the attacker got in. A rebuild that uses the same vulnerable plugin, the same passwords or the same infected hosting account can be hacked again just as quickly.

Need a hand?

Let me clean your WordPress site for you

Send me your site URL and what you're seeing. I'll reply with what I think is going on and the next step.

$95 per infected site · 1-month guarantee · direct contact with the specialist

Get My Site Cleaned →