How to Clean a Hacked WordPress Site

Find the planted files and injected code, contain the damage, and confirm your WordPress site is safe to reopen. Do it by hand, or let WP Care run the checks.

Your homepage looks fine while you’re logged in, but a customer says it sends them to a different site. A redirect that only affects some visitors is a common symptom of a compromised website. Start by writing down exactly what the customer saw, then work backward to what served it.

This guide uses WordPress paths and walks through the investigation, cleanup, and recovery. Every check here can be done by hand. Most of them can also be run for you: WP Care scans the files and the database, flags what doesn’t belong, and lets a developer quarantine it. Both routes are covered below so you can see what each one involves. Google’s examples of hacked content

Signs your site is compromised

A hacked site rarely announces itself. These are the reports that usually come first:

  • Redirects for some visitors only. Mobile users or people arriving from Google land on a different site, while logged-in administrators see the normal page.
  • Search results you didn’t write. Titles and snippets in Google mention pharmacy products, casinos, or text in another language, or pages you never created show up under your domain.
  • Browser or host warnings. Chrome shows a red “deceptive site” screen, your host suspends the account, or Search Console emails you about a security issue.
  • Accounts and files you don’t recognize. A new administrator, an unfamiliar plugin, or PHP files with recent dates in folders nobody has touched.
  • Unexplained load. The site slows down, sends email you didn’t write, or uses far more CPU and disk than its traffic explains.

One of these is enough to start the checks below. None of them tells you where the code lives yet.

From the first report to reopening the site
  1. Confirm

    Record the affected page, the time, and what the visitor saw. Check what changed.

  2. Contain

    Limit exposure and preserve copies and logs for investigation.

  3. Recover

    Rebuild or restore from a trusted source and close the entry point.

  4. Verify

    Test the affected pages and key business flows, then monitor the site after reopening.

Start with a scan

Run two scans before you change anything, so you have a record of the starting state.

  • From the outside. Pinpoint checks the public site without installing anything: exposed WordPress endpoints, security headers, DNS and reputation signals, and TLS. Save the report. It shows what a visitor or an attacker can see.
  • From the inside. An outside scan can’t read your files or database. That takes either a tool running on the site, such as WP Care, or the manual checks later in this guide.

Confirm what changed

  • Check what visitors see. Record the original URL, the destination if there was a redirect, the time and time zone, and whether the visitor came from search or used a phone. Ask for a screenshot if they have one. Use a trusted scanner or an isolated test browser to check the affected pages while signed out. Avoid opening suspicious downloads or entering credentials during testing.
  • Check outside reports. Open the Security Issues report in Google Search Console. Look for unfamiliar pages, changed search snippets, and browser or hosting alerts. Search Console can show sample affected URLs, so check beyond those examples. Search Console Security Issues report
  • Compare with a known baseline. Review hosting access and error logs, recent deployments, plugin updates, new administrators, and unexpected password resets. Match what changed to the incident timeline. A new redirect rule, unknown administrator, or file that differs from its trusted release gives you a concrete lead. Legitimate updates and cache jobs can also change timestamps. WordPress guidance for hacked sites

Contain the incident and save evidence

Contact your host. If the site is sending visitors to phishing pages, serving malware, or exposing accounts or payments, ask the host to isolate it or serve a maintenance page outside the compromised WordPress installation. Save a restricted copy of the files, database, and available logs before removing anything. Record affected URLs, timestamps, screenshots, and any file paths you find. Keep this incident copy separate from backups you would restore. On shared hosting, ask the host to check other sites in the same account.

Use a trusted device and the host’s verified login to revoke suspicious sessions and block compromised access. If you suspect customer data was exposed, bring in whoever handles privacy and incident response so they can assess what was affected and any notification deadlines. WordPress incident guidance · CISA incident response guidance

Let WP Care do the searching

WP Care is our WordPress maintenance service. Each site on a plan is connected to our WPCARE dashboard, which runs the checks in this guide on a schedule and on demand. During an incident, this is what it covers:

  • Malware file scan. Walks the whole file tree, hashes every file, and matches the results against known threat signatures. Planted PHP in wp-content/uploads and backdoors hidden among plugin files show up as findings with their full path.
  • Core integrity check. Compares WordPress core files against the official checksums for the installed version, so a modified wp-includes file or an extra file in the site root is listed instead of hunted for.
  • Database scan. Searches posts, options, and users for injected scripts and suspicious markup, which is where redirects often survive after the files are clean.
  • Plugin vulnerability check. Lists installed plugins with known vulnerabilities and pending updates. This is usually the fastest route to the entry point.
  • Hardening checks. Tests the public site for missing security headers, insecure cookies, version disclosure, open application passwords, debug mode, backups left in the web root, and weak administrator usernames.
  • Quarantine and restore. A confirmed malicious file is moved out of the site into protected storage. It stays restorable for seven days in case it turns out to be legitimate, and every action is logged.
  • Backups, uptime, and alerts. Scheduled backups give you a restore point, and alerts fire when malware is found, a plugin becomes vulnerable, a backup fails, or the site goes down.
  • Client reports. Findings and fixes are collected into a report you can hand to the site owner.

A developer reviews the findings, decides what to quarantine, and closes the entry point. If your site isn’t on WP Care, the same work is done by hand, one location at a time.

Without WP Care: the manual checks

Plan for several hours on a small site and longer on a store or a site with many plugins. You need SFTP or SSH access, database access, and clean copies of everything installed. Work on a restricted copy where you can, and keep notes on every file you touch.

Review files, the database, and account access

Check files by path and provenance

  • Core and the site root. Start with wp-admin, wp-includes, and files in the WordPress root. From a trusted environment, wp core verify-checksums --include-root compares core files against WordPress.org for the installed version and locale without booting WordPress. Extra root files and checksum mismatches need review. The check does not cover your database, uploads, or custom code. WP-CLI core checksum documentation
  • Themes and plugins. Compare the active theme and child theme, plugins, and custom code against trusted release packages or version control. WordPress.org plugin checksums are available for many releases. Compare premium and custom plugins with the vendor’s clean package or a known-good Git revision. Check wp-content/mu-plugins and drop-ins such as object-cache.php and advanced-cache.php with your host. These files may be legitimate parts of the hosting setup. WordPress plugin checksum guidance · Must-use plugins
  • Uploads and generic filenames. Look for unexpected PHP under wp-content/uploads, especially among ordinary images and documents. An unfamiliar cache.php, update.php, or wp-helper.php in a dated media folder deserves a closer look. So does an image-like name such as photo.jpg.php. Those are examples of names to investigate. Compare the full path, contents, and origin before deciding what to quarantine. Even index.php can be a legitimate file. Inspect suspect files as text in a restricted copy without executing them or opening them through a public URL.
  • Recently changed files. List files modified around the time of the first report and sort them by date. Attackers can reset timestamps, so treat a clean date list as one signal and keep checking contents.
  • Configuration and scheduled jobs. With your host, check wp-config.php, .htaccess on Apache, server redirects, PHP settings such as .user.ini where used, and host-level or WordPress scheduled jobs. Look for changes you cannot trace to your host, deployment, or a known plugin. Check the CDN and tag manager too if they can change what the browser receives. WordPress hacked-site file checks · PHP per-directory configuration

Trace injected code in the header and elsewhere

Compare the original page response with what the browser displays in a safe test environment. An unexpected Location header on a redirect response points you toward server, CDN, or application redirect rules. An unfamiliar <script> in the HTML <head>, an iframe, or new hidden links point you toward whoever generated that markup. If a script only appears after the page loads, use the browser’s Network panel to see which request initiated it and compare the domain with the site’s approved vendor list. In PHP and JavaScript, a newly added block of unreadable code is worth comparing with a clean copy. Legitimate bundled scripts can be hard to read too.

On a classic theme, check header.php, footer.php, and functions.php in the active theme and child theme. On a block theme, check the Header and Footer in the Site Editor and compare them with the files under the theme’s parts folder. A saved block template part can override the file on disk. Also review header and footer snippet plugins, Custom HTML blocks, widgets, and tag manager revisions. WordPress template parts

Search the database

Injected code often lives in the database, where a file scan can’t see it. On a protected copy, and using the table prefix for your installation, check:

  • wp_options. Compare siteurl and home with the real address. Review autoloaded options, widget content, and settings from header and footer snippet plugins for scripts you didn’t add.
  • wp_posts and wp_postmeta. Search post content, reusable blocks, and template parts for <script>, <iframe>, and links to domains you don’t use. Check for published posts and pages nobody on the team wrote.
  • Scheduled events. Review the WordPress cron list for hooks that don’t belong to core, the theme, or an installed plugin.

Avoid a blanket search-and-replace on the live database. It can damage plugin settings or remove legitimate content. WordPress database migration guidance

Review users and access

Open the Users screen and sort by role. Remove administrators nobody can account for, and check the registration date and email of the ones that remain. Review application passwords on each administrator profile, and check hosting, SFTP, and database accounts for users added outside WordPress. Attackers often leave an account behind so they can return after the files are cleaned.

Rebuild from trusted sources and close the entry point

  1. Restore or rebuild in isolation. Verify that a backup predates the likely compromise and contains both files and database. If you can’t establish that, rebuild using fresh WordPress, plugin, and theme packages and migrate only reviewed content, uploads, and settings. Replace entire compromised components from clean sources. Copying clean files over old folders can leave extra files in place. Keep staging from sending live emails, taking payments, or running production integrations. WordPress backups
  2. Remove the way back in. Patch or replace the vulnerable component, remove unauthorized accounts and jobs, and verify permissions with your host. If you can’t establish the entry point or suspect compromise beyond the site, work with the host before reusing that environment.
  3. Rotate access on the clean environment. Change affected passwords and keys for hosting, SFTP or SSH, WordPress, the database, and connected services. Revoke unknown application passwords and sessions. Replace WordPress authentication keys and salts to invalidate existing login cookies, then update legitimate integrations to use the new credentials. WordPress hardening guide · WordPress key and salt configuration

Example of a redirect that survives file cleanup

An online shop gets two reports of mobile visitors being sent to an unfamiliar site. The team finds an unexpected PHP file among dated uploads and saves a copy for investigation. It also finds a script on several product pages. The theme files match their trusted release, but the Site Editor has a saved Header template part with an unauthorized HTML block. The team removes the injected block from the cleaned copy and verifies the same product URLs while signed out. The two findings need separate verification. The team checks logs and accounts before assuming they came from the same incident path.

A file-only cleanup would have removed the uploaded PHP file and left the redirect in place, because the block was stored in the database. That is why the file scan and the database scan are run together.

Keep the site clean after recovery

A cleaned site that keeps the same weak points tends to get reinfected within weeks. Three tools cover the follow-up:

  • WP Stack Security adds hardening controls, security checks, and activity logs inside WordPress, so the next unexpected change has a record.
  • WP Care keeps the scans, updates, backups, and alerts running, with a developer following up on findings.
  • Pinpoint gives you an outside view. Rerun it after the cleanup and compare the report with the one you saved at the start.

Verify the site and monitor after reopening

0 of 6 checked

For routine checks after recovery, use our WordPress Security Checklist. If you’d rather hand over the incident, our WordPress Security service covers incident review and malware cleanup.

Share

Have a project like this in mind?

Tell us what you need — we reply within one business day.

Start a conversation