ShieldThemes Web Development
+1 (415) 555-0142 Get a quote →
← Journal/Security

How to Restore Hacked WordPress Files Safely

This guide walks you through restoring hacked WordPress files without losing valuable data, emphasizing evidence preservation and controlled recovery methods.

Leo Tanaka
Leo Tanaka
Head of DevOps · Sep 29, 2026 · 19 min read
How to Restore Hacked WordPress Files Safely

You open your store before the first customer arrives and find visitors redirected to an unfamiliar page. The layout is broken, an unknown administrator appears in WordPress, or your host displays a security warning. You start asking how to restore hacked WordPress files without erasing today’s orders, form submissions, customer accounts, or settings.

Most hacked WordPress sites don’t have a simple file-replacement problem. They have a trust-and-recovery problem. Malicious code may sit in core files, plugins, themes, uploads, or configuration, while valuable business data remains in the database. The right backup, files, and access records all need review.

A controlled recovery path starts by isolating the site and preserving evidence. You then separate file recovery from database review, replace contaminated code, validate content and access, scan, and monitor before reopening. ShieldThemes uses that sequence to protect usable data while closing the access path that caused the compromise.

Why Restoring Only the Visible Damage Leaves the Site Exposed

When your WordPress site shows a redirect, warning, or broken layout, the visible symptom is rarely the whole compromise. If you delete one unfamiliar script and reopen the site, another backdoor may remain in a plugin, theme, upload, or configuration file. Your customers may still face redirects, stolen sessions, or unsafe downloads.

That incomplete restore also creates an operational cost. A 2022 survey by WP White Security found that 43% of administrators spent up to three hours each month on security work. Recovery should reduce repeat work, not create another cycle of emergency edits, ranking loss, customer complaints, and reinfection.

Infographic showing a compromised WordPress site moving from isolation to verified recovery to prevent hidden backdoors
Hidden backdoors risk after partial restoration

Take the Site Offline Before Editing Evidence

Your first decision is containment, not deletion. Put the site into maintenance mode or restrict access at the hosting layer, then preserve a snapshot of the current files and database. Record redirect destinations, suspicious administrator accounts, warning messages, file timestamps, and the first time you noticed the problem.

The practical principle is clear:

Preserve evidence and a contaminated backup before changing files or reopening the site.

A backup created after infection may preserve the attacker’s foothold. The current copy may be damaged, but deleting it can remove the only record showing how access was gained. Keep the contained copy for comparison while restoring trusted files elsewhere.

Separate Visitor Protection From Permanent Cleanup

Taking the site offline protects visitors now. It does not prove that the permanent restore is clean. Search engines may lower visibility after harmful redirects, customers may lose trust after seeing a warning, and exposed credentials or order data may require a separate response. File recovery must account for both public risk and hidden access.

Weak recovery: Delete wp-content/uploads/cache.php and reopen the store because the redirect has stopped.

Stronger recovery: Preserve the original copy, replace trusted core and extension files, then review uploads, administrator accounts, configuration, and database content before reopening.

Use the Backup Rule Before You Delete Anything

Don’t treat the newest backup as automatically safe. Check when it was created against the first symptom, and retain at least one contaminated copy before changing files. If your host allows it, clone the site into a contained workspace and perform recovery there. ShieldThemes can help with that process, although a simple host snapshot may be sufficient for a small site.

Practical rule: Take a snapshot or export first, record timestamps and symptoms, and work on a contained copy whenever your hosting environment allows it.

Choose Between a Clean Backup, File Replacement, and a Fresh Rebuild

You can usually recover a hacked website, but the safest route depends on three facts: when the infection began, whether a backup is truly clean, and how much current database data you must preserve. A clean backup may remove the malware while also deleting recent orders, form submissions, comments, or product updates.

Don’t choose the oldest backup by default. Malware may have stayed hidden for weeks, leaving that copy infected too. One.com advises creating a recent backup before changing anything, so you retain access to your files and content if recovery goes wrong, according to One.com.

Decision flowchart comparing clean backup, trusted file replacement, and fresh rebuild options for hacked site recovery
Choosing the safest recovery method

When a Hacked Website Can Be Recovered

Yes, usually. Restore a confirmed clean backup when losing newer database records is acceptable. If your store must retain recent orders, replace compromised files while reviewing the database separately. One.com also documents a control-panel restore that can return a site with one click, though a shortcut does not prove that the selected backup is clean.

Use a Clean Backup When Its Infection Date Is Known

Choose this route when you can date the compromise and verify a backup created before it. Test the copy first, then restore it, rotate credentials, and update the software. If the oldest available backup predates the infection but contains stale customer data, the data loss may still outweigh the file cleanup.

Replace Trusted Files When the Database Must Stay Live

Replace WordPress core, plugins, and themes with fresh files from trusted sources when current orders and submissions matter most. Keep the database isolated for inspection. This route preserves valuable records, but hidden PHP files, altered uploads, scheduled tasks, or malicious database entries still require review. ShieldThemes can support this controlled recovery, although a small site may manage it with a careful host-led process.

Rebuild on a Clean Install When the File System Is Widely Compromised

Use a fresh installation when many directories contain unknown files, no backup is trustworthy, or the oldest backup is already infected. Import only reviewed database content, media, and settings. This takes longer, but it gives you a cleaner boundary than repairing every suspicious file in place.

situation better move
A dated backup is confirmed clean and current database loss is acceptable Restore the known-clean backup, then update credentials, software, and security controls
Files are compromised but recent orders, submissions, and content must be preserved Replace core, plugins, and themes from trusted sources while reviewing and retaining the database separately
The file system is broadly contaminated, no clean backup exists, or the oldest backup is already infected Create a fresh installation and import a carefully inspected database export
A community post recommends a backup restore without showing its creation date or verification method Treat it as a lead only; test the backup in isolation before using it on production

What Works

  • Test first: Restore into an isolated copy before touching your live store.
  • Preserve evidence: Keep the infected files, timestamps, and database export for comparison.
  • Match the route to the data: Protect recent orders when database records matter more than configuration speed.

What Fails

  • Blind restoration: A backup without a known creation date may restore the backdoor.
  • Forum certainty: Reddit instructions can suggest commands, but they cannot verify your backup’s integrity.
  • Production testing: Experimenting on the live site can destroy evidence and customer data.

How Reddit Advice Fits Into Recovery

Reddit can provide recovery leads, but forum advice cannot confirm that your backup is clean or suitable for a production store. Use those instructions only to shape questions for your host or developer. The safer next step is an evidence-preserving test restore, followed by the route that protects your most valuable current data.

Prepare the Evidence, Access, and Recovery Workspace

Before removing a suspicious file, set up a contained recovery workspace. Preserve what happened, secure access, and identify whether the damage sits in your files, database, or both.

You can then choose a recovery route without destroying useful evidence or recent customer data. One.com advises changing passwords as the first response to a suspected hack, including FTP or SFTP and database passwords. Your hosting control panel may also show a list of malware-infected files, but that list is a lead, not proof that every infected file has been found.

Checklist of pre-recovery tasks including securing access credentials, backups, logs, and database exports
Pre-recovery preparation checklist

How to Tell If WordPress Has Been Hacked

You may have a confirmed compromise when you see several unusual signals together. Check your site from a trusted device, then record each symptom before changing anything.

  • Unexpected redirects: Your pages send visitors to unfamiliar domains, downloads, or fake login screens.
  • Unknown administrators: Your WordPress user list contains accounts nobody at your business created.
  • Changed files: Your theme, plugin, or core files show unfamiliar edits or recent timestamps.
  • Injected links: Your posts, footer, or source code contains hidden gambling, pharmaceutical, or foreign-language links.
  • Hosting alerts: Your host reports malware, unusual processes, suspended files, or suspicious activity.
  • New scheduled tasks: Your server or WordPress scheduler contains jobs you cannot explain.
  • Abnormal activity: Your access logs show unfamiliar login locations, repeated administrator attempts, or unexplained traffic spikes.

Collect Hosting, SFTP, Database, and Administrator Access

You need working access to your hosting panel, SFTP or FTP, database tool, WordPress administrators, business email, and payment-related accounts. From a trusted device, record the current access state, then change each credential through the relevant provider. Keep the old usernames, timestamps, alerts, and login locations for investigation rather than deleting the record.

Record a Snapshot Before Removing Suspicious Files

Export a complete file archive, database backup, control-panel alerts, malware reports, access logs, and relevant timestamps. Add a short list of recent business changes, such as a plugin installation, developer handoff, theme update, or payment integration. Your control panel’s infected-file report can guide review, but it cannot establish that the entire compromise has been found.

Decide Whether Recent Data Must Survive the Restore

Separate file symptoms from database symptoms before selecting a restore. If your files look altered but orders, accounts, or content changed recently, preserve the database for separate review. If the database contains unfamiliar users, options, posts, or scheduled entries, a clean file replacement alone may not remove the threat.

Contain the site and preserve evidence first. Then restore trusted files or handle the database separately without sacrificing legitimate business data.

Restore Trusted WordPress Files Without Erasing Site Data

Protect your pages, orders, customer accounts, and submissions by separating file restoration from database review. Don’t overwrite everything with an old backup before you know which records remain valid.

Take the site offline first, preserve separate copies, replace code from trusted sources, and validate each layer before reopening. One.com also advises taking a compromised site offline to block attacker access and protect visitors and search visibility.

Step-by-step WordPress recovery process from site isolation to verified reopening after file restoration
Sequential WordPress recovery workflow, wordpress.org, screenshot taken 28 September 2026

How to Restore Hacked WordPress Files Without Losing Data

Restore hacked WordPress files safely by replacing contaminated code while keeping the current database as a separate recovery object. That sequence preserves legitimate content without carrying malicious files into the rebuilt site.

Isolate the Site and Revoke Active Access

Place your site behind a maintenance barrier or take it offline, then change hosting, FTP, SSH, WordPress, and database credentials from a clean device. Disable unknown administrator accounts without deleting evidence, and record the time of every action.

Create a Forensic Copy and Export the Database

Create clearly labelled, separate copies of your current files and database before editing anything. Keep one untouched copy for investigation and another for recovery work. Export pages, posts, users, orders, and form submissions, but don’t treat an old backup as automatically clean.

  • File copy: Store the original directory outside the public web root.
  • Database export: Save a dated SQL export and verify that it opens.
  • Access log: Record suspicious users, redirects, timestamps, and hosting alerts.
priority what to check why
1 Site status, hosting access, current files, and database export Contain the compromise and preserve a rollback and investigation copy
2 WordPress core, plugins, themes, uploads, and configuration files Replace contaminated code while retaining legitimate media and settings selectively
3 Users, options, redirects, scheduled tasks, orders, and form submissions Detect database manipulation and protect current business records
4 Credentials, malware scan results, administrator flows, and customer journeys Prevent immediate re-entry and confirm the restored site works safely

Replace WordPress Core, Themes, and Plugins With Trusted Files

Replace WordPress core with a verified release, then reinstall every plugin and theme from its official source or a known-good package. Never reuse unknown copies. Inspect uploads for executable files, unexpected scripts, and altered media, then review configuration files.

Before: DB_PASSWORD still contains the old database credential.

After: Update the database password and its value in wp-config.php; One.com warns that leaving the old value can cause connection errors.

Validate the Database, Credentials, and Recovered Site

Review administrator accounts, suspicious options, redirects, scheduled tasks, and serialized data before reconnecting the restored files. Reset credentials again, scan the complete site, and test login, checkout, orders, forms, and customer journeys.

ShieldThemes can manage this file-and-database separation for a growing business with active transactions, although a complex compromise may still require hosting-provider or forensic support.

Handle Persistent Backdoors, Unknown Infection Dates, and Large Sites

If you cannot identify the infection date, you cannot assume any backup is clean. Compare restore points, isolate the site, and treat every overlooked location as a possible hiding place.

The recovery path also changes when uploads contain scripts, configuration files keep changing, or your store cannot tolerate repeated production edits. Use a staged clone, immutable exports, access logs, and a controlled release window before service returns.

Layered recovery diagram illustrating staging, scanning, access control, and controlled production release
Layered approach for complex site recovery

Trace the Earliest Trusted Restore Point

When you don’t know when the compromise began, restore only from a point supported by file timestamps, access logs, scan results, and known business activity. A rapid rebuild may restore sales sooner, but shallow investigation can carry the backdoor into the next release.

Before: wp-config.php loads a newly added file from /tmp/cache.php.
After: wp-config.php loads only the documented configuration and trusted WordPress files.

Treat Uploads, Configuration, and Scheduled Tasks as Separate Risks

Inspect uploads for executable extensions, modified configuration files, unknown administrator accounts, database options, cron events, and hosting-panel access. A clean theme directory does not prove that the site is safe.

Automation improves consistency for inventories and repeated scans. Expert review is still needed for ambiguous code, serialized data, custom integrations, and customer records.

Use Staging and Repeatable Scans for Stores and Multisite Networks

Clone a high-traffic store or multisite network into staging, preserve immutable database and file exports, then test restoration in a release window. Run the same file, database, access, and checkout checks after each remediation pass instead of trial-editing production.

What Works

  • Contained clone: You can investigate without exposing customers or corrupting live orders.
  • Access logging: You can connect file changes with hosting, administrator, and deployment activity.
  • Repeatable scans: You can compare results after every restore and release.

What Fails

  • Blind backup reuse: You may restore the original backdoor with the website.
  • Manual repetition: You can miss the same hidden location across multiple sites.
  • Production experiments: You risk lost orders, broken integrations, and customer exposure.

Undoing a Hack Through Layered Access Controls

There is no single undo button. To undo getting hacked, you need containment, eradication, credential rotation, validated restoration, and monitoring across WordPress, hosting, databases, deployment tools, and third-party services.

ShieldThemes can run a managed security and maintenance workflow when your internal team lacks time or forensic confidence. That approach reduces repeated manual edits, although complex compromises may still require host support or specialist forensic investigation.

Fix WordPress Recovery Errors That Cause Reinfection

A restored WordPress site can look normal while attackers still have access. You may see a clean homepage, yet administrator sessions, checkout flows, scheduled tasks, redirects, or hidden files remain compromised.

A reported full compromise showed how a site can appear fixed, then become infected again within days. When you lack a usable backup, broad file restoration can hide the real failure. Recovery isn’t complete until you validate files, databases, credentials, extensions, and critical user journeys.

The Backup Was Already Infected

If your site returns to the same condition after restoration, you may have selected a backup that already contained malware. Isolate the current copy, preserve evidence, and test older restore points before trusting any backup.

symptom likely cause first fix
The site returns infected within days of restoration The selected backup already contained malware or a hidden backdoor was missed Isolate the site, preserve the current copy, test older backups, and consider a fresh rebuild
New logins or suspicious activity continue after cleanup Hosting, FTP or SFTP, database, email, or administrator credentials were not rotated Change credentials from a trusted device and update every dependent configuration
Redirects or malicious links reappear after files are replaced Injected database options, posts, widgets, or scheduled tasks remain active Review database content and scheduled tasks, then rescan after removal
A plugin appears clean but reinfection continues An unsafe copy, nulled extension, or vulnerable version was reinstalled Remove it and install a verified current release from a trusted source
The homepage works but checkout or login behaves abnormally The site was reopened before administrator and customer flows were validated Keep the site contained and test critical journeys, redirects, logs, and scans

The Attacker Still Has a Valid Credential

Cleaning files does not remove access you left active. Rotate hosting, SFTP, database, email, administrator, deployment, and API credentials from a trusted device, then update every connected configuration.

  • Preserve access records: Save relevant login and hosting logs before changing accounts.
  • Remove unknown users: Review administrator accounts, application passwords, tokens, and active sessions.

The Database Was Restored Without Reviewing Injected Content

Your database can store malicious redirects, options, widgets, posts, and scheduled tasks even after trusted files replace the infected copies. Inspect altered content and rescan after removal instead of relying on a working browser page.

The Site Was Reopened Before a Second Scan

Reopening your site after one cleanup pass gives missed malware a chance to run. Keep it contained until you validate administrator access, customer journeys, checkout, redirects, logs, scheduled tasks, and another scan. No single scanner guarantees eradication.

After every fix, review the logs and scan again. A browser check confirms appearance, not trust.

Verify the Restore and Put Protection on a Maintenance Cycle

You haven’t finished recovery when the homepage looks normal. You need observable proof across files, database behaviour, customer journeys, search visibility, and access logs before reopening the site fully.

Your acceptance check should show that trusted files remain unchanged, unauthorised access has stopped, and scheduled activity is expected. If any check fails, keep the site contained, preserve evidence, fix the cause, and scan again.

Confirm File Integrity and Database Behaviour

Compare your current core, theme, plugin, and upload inventories with trusted copies, then confirm that every version is current and expected. Review configuration files, database administrators, injected options, unknown posts, and altered widgets before approving the restore.

  • Files: Your core and extensions match trusted inventories, with no unexplained executable files in uploads.
  • Database: Your users, options, posts, and permissions contain no unauthorised additions or injected code.
  • Tasks: Your scheduled tasks have known owners, expected timing, and a legitimate purpose.

Test Public, Administrator, and Transaction Flows

Test your administrator login, password reset, registration, contact forms, checkout, order creation, email delivery, and key integrations from a clean browser session. You should see the expected response, receive the expected email, and find no unfamiliar redirect or error.

Use a specific maintenance record. Weak: “Site checked after cleanup.” Strong: “March 12, 2026: checkout, password reset, Stripe webhook, and customer email tested successfully.”

Check Search, Redirects, Logs, and Scheduled Tasks

Check your indexed URLs, browser warnings, Search Console security notices, redirects, server access logs, and cron activity. Repeated suspicious requests, new redirects, or unexplained tasks mean the site is not ready to reopen.

When Wordfence flags malicious changes, its documented workflow recommends repairing each flagged file until the list is empty, then running another scan. Treat that as a tool-specific process, not proof that every compromise is gone.

How to Protect a WordPress Website From Hackers After Recovery

To protect your WordPress website from hackers, turn recovery into ongoing maintenance. Use tested backups, timely updates, least-privilege accounts, available MFA, monitoring, vulnerability reviews, hardened hosting, and a documented incident plan. Rescan after every meaningful change.

Escalate to ShieldThemes when your site is high-traffic, transactional, multisite, or repeatedly reinfected. Its senior team can provide an accountable partner for security and ongoing maintenance, though complex incidents may still require your hosting provider or specialist forensics support.

FAQ

How to recover a hacked WordPress site

Start by isolating the site and preserving a complete copy of its files and database. Record redirects, suspicious users, alerts, and access times before changing anything. Then identify when the compromise began, restore trusted WordPress core, themes, and plugins, review the database, rotate every credential, and test the site before returning it to normal service.

How to tell if WordPress has been hacked

Common signs include unfamiliar administrator accounts, unexpected redirects, changed files, new plugins, altered settings, spam pages, browser warnings, or emails sent without your approval. Compare the site with a known-clean copy and review hosting, WordPress, FTP, SSH, and database logs. A single symptom isn't proof, but several together deserve immediate containment and investigation.

Can a hacked website be recovered

Yes, most hacked WordPress sites can be recovered when you can access the hosting account, a usable database, or a clean backup. Recovery may require replacing the code and reviewing customer or order data rather than simply restoring every file. If the compromise reached payment systems or personal data, involve your host and an experienced security team promptly.

How to undo getting hacked

You can't reverse the original intrusion, but you can remove its access and repair the damage. Preserve evidence, isolate the site, replace compromised code with trusted versions, delete unverified accounts, rotate hosting and administrator credentials, and enable monitoring. Check logs and database content for changes, then fix the entry point so the same weakness doesn't reopen the site.

How to restore hacked WordPress files from Reddit guidance

Reddit discussions can suggest useful checks, but they are anecdotal and may omit the details of your hosting setup or infection. Don't copy commands or overwrite files based on a post alone. Use those threads as prompts, then confirm the approach against a clean backup, trusted WordPress packages, your host's advice, and a review of the database.

Start With One Contained Copy, Then Restore in Order

Recovery needs a clear order, not another quick change on the live site. Protect your evidence, customer data, and next decision by working from one contained copy before touching production.

The fastest visible fix isn’t always the safest fix. You may restore an earlier backup quickly, yet reintroduce malware if that backup was created after the compromise began.

1. Isolate and Preserve

  1. Isolate the site: Put your WordPress site into maintenance mode or restrict access through your host before making changes.
  2. Preserve a copy: Use your hosting control panel to create a complete file archive and database export. Keep both outside the live account.
  3. Record the evidence: Write down your symptoms, timestamps, suspicious accounts, redirects, alerts, and recent access activity before anything changes.

2. Choose and Restore

  1. Choose the route: Select a verified clean backup, trusted-file replacement, or fresh rebuild based on the infection date and the condition of your database.
  2. Replace trusted code: Restore WordPress core, themes, and plugins from trusted sources while preserving only the site data you have reviewed.
  3. Review business records: Check your pages, orders, customer accounts, forms, settings, and database content for unauthorised changes.

3. Validate and Secure

  1. Rotate access: Change your hosting, database, WordPress, administrator, FTP, SSH, and API credentials, then remove accounts you cannot verify.
  2. Validate journeys: Test your administrator login, customer registration, checkout, payments, forms, email delivery, and important redirects.
  3. Scan twice: Run a scan after restoration and again after your configuration changes. Reopen only when both checks are clean and monitoring is active.

Start With the Hosting Backup and Access Page

Today, open your hosting control panel or backup screen and create one contained copy. Don’t edit production files until that copy exists. Preserve the evidence first. That discipline is safer than speed, especially when your business cannot risk losing transactions or customer data.


If you want help with the process, ShieldThemes provides controlled WordPress recovery, trusted file restoration, security checks, and ongoing maintenance for businesses protecting customer data and transactions. You can find practical guidance in the ShieldThemes development and security articles.

Leo Tanaka
WRITTEN BY
Leo Tanaka
Leo runs our hosting and infrastructure practice — CI/CD, cloud cost, observability and the on-call rotation behind every care plan.
All articles by Leo Tanaka →
Want this on your project?
Get a fixed-price quote from a senior lead within 24 hours.
Request a quote →

Keep reading

WordPress to Shopify Migration Checklist
Shopify · 16 min
WordPress to Shopify Migration Checklist
How we shipped a support agent that resolves 62% of tickets
AI · 5 min
How we shipped a support agent that resolves 62% of tickets
What to learn in the two weeks before a website redesign
Design · 5 min
What to learn in the two weeks before a website redesign