THE SHORT ANSWER
Do not start deleting files. First confirm the hack and take the site offline or behind maintenance mode. Copy the infected files, database and server logs as evidence. Then reset every credential (WordPress users, hosting, SFTP, database, salts, API keys). Only after that, clean or rebuild from known-good sources, harden, and request a review in Google Search Console.
A hacked site feels like an emergency, and the instinct is to start deleting things. That instinct causes most failed cleanups. Deleting files before you understand the break-in destroys the evidence that tells you how the attacker got in, and if you do not close that door, the site is reinfected within days.
This guide gives you a plan for the first hour, minute by minute, and then the full recovery: cleaning, restoring, hardening, getting Google warnings removed, and telling the client. It is written for site owners and for agencies looking after many client sites, where one hacked site can mean a shared password or a shared server problem.
Applies to: Self-hosted WordPress 6.x on Apache, LiteSpeed or Nginx hosting, with or without WP-CLI access Last verified: November 2026.
01Quick reference
| Error | Most likely cause | Try first |
|---|---|---|
| Redirects to spam for some visitors | Injected .htaccess rule, JavaScript in the database, or a PHP backdoor | Check .htaccess and search the database for script tags |
| Spam pages indexed in Google | Spam page generator in a PHP file, often with a fake sitemap | Search site:yourdomain.com and look for new files |
| Red browser warning on the site | Google Safe Browsing flagged malware or phishing | Open the Security issues report |
| Unknown admin users reappear | Backdoor file, mu-plugin or cron job that recreates the user | Check mu-plugins and cron events |
| Reinfection after cleanup | Entry point not closed, or a backdoor left behind | Read the access logs around the reinfection time |
| Hosting suspended for malware | Host scanner found infected files or outbound spam | Ask the host for the list of flagged files |
02The first 60 minutes at a glance
Print this table or keep it open. The order matters more than speed. Every step protects something the next step needs.
| Time | Step | Goal |
|---|---|---|
| 0 to 5 min | Confirm it is a hack, not a broken update or a host problem | Avoid a cleanup you do not need |
| 5 to 15 min | Contain: maintenance mode, block traffic or take the site offline | Stop harm to visitors and further damage |
| 15 to 25 min | Preserve evidence: full backup of files, database and logs | Keep the clues to how they got in |
| 25 to 40 min | Reset access: hosting, SFTP, SSH, database, WordPress users, salts, application passwords, API keys | Lock the attacker out |
| 40 to 50 min | Call or ticket the host with specific questions | Find out about server-side issues and clean backups |
| 50 to 60 min | Assess scope and decide: clean in place, restore, or rebuild | Pick the recovery path with facts, not panic |
Notice what is not in the first hour: deleting files, running a one-click cleaner, or updating plugins. Those come after you know what happened. The WordPress.org hacked site FAQ follows the same logic: stay calm, document, scan, check with the host, reset access, and back up the infected site for forensics before replacing anything.
Still broken after these steps?
Send us the URL and the exact error. Fixes start from $59, with a fixed quote within 24 hours and an NDA if you need it.
03Minutes 0 to 15: confirm and contain
Confirm it is really a hack
Plenty of things look like a hack and are not. A plugin update that breaks the layout, an expired domain showing a parking page, or a host outage are all common. Signs that point to a real compromise:
- Visitors, especially on mobile or from Google, are sent to spam, pharma, casino or fake prize pages, while you see a normal site when logged in.
- Google results show titles in Japanese or other languages, or pages you never created.
- Chrome or another browser shows a red warning, or Search Console reports a security issue.
- There are admin users you do not recognize, or your own admin account no longer works.
- The host suspended the account for malware or sent a spam-sending notice.
- Files you did not upload appear, such as PHP files in
wp-content/uploadsor odd names in the root.
Check from a private window, from your phone on mobile data, and with a Google search for site:yourdomain.com. Many hacks hide from logged-in admins on purpose. If you only see a broken layout or a critical error, our WordPress errors fix guide is the better starting point.
Write down what you see
Take screenshots with the URL bar visible and note the time and time zone. Write down any recent changes: plugin installs, new users, theme edits, password shares. This takes two minutes, and it is the timeline you will match against the logs.
Contain the damage
Your goal is to stop visitors from being harmed while you work. Pick the lightest option that does the job:
| Option | When to use it | Trade-off |
|---|---|---|
| Maintenance page from the host panel | Most hacks, if the host offers it | Does not touch WordPress files |
| Password protect the site at the server or host level | Spam redirects, malware served to visitors | Search engines and visitors see a login prompt |
| Cloudflare block or challenge rule for all visitors except your IP | Site already behind Cloudflare | Needs care to keep your own access |
| Take the site offline (host disables it) | Card skimming, phishing pages, active data theft | Full downtime, but stops harm fastest |
Avoid maintenance mode plugins at this stage. Installing a plugin on a compromised site writes new files and changes timestamps, which muddies the evidence. If you use Cloudflare, our Cloudflare security guide shows how to write a rule that challenges everyone except your own IP.
For an online store, treat a hack as possible card or customer data exposure until you know otherwise. Taking a store offline for a few hours costs less than skimmed cards.
04Minutes 15 to 25: preserve evidence before you clean
This is the step most guides skip or put after the cleanup. It has to come first. Once you delete the malicious files and restore a backup, the record of how the attacker got in is gone, and you are guessing.
Back up the infected site
Take a full copy of the files and the database, label it clearly as infected, and store it off the server. Never restore it. It exists only for investigation. With SSH and WP-CLI:
cd /path/to/site
wp db export ../INFECTED-db-$(date +%F-%H%M).sql
tar -czf ../INFECTED-files-$(date +%F-%H%M).tar.gz .Without SSH, use the host's backup tool or file manager to download the whole site folder and export the database from phpMyAdmin.
Save the server logs
Access logs and error logs are the best evidence you have, and many hosts rotate them after a few days. Download the raw access logs from the host panel now. In the logs, look for POST requests to unusual PHP files, requests to wp-login.php or xmlrpc.php from the same IP, and the first request to any file you know is malicious. If you have a WordPress activity log plugin, export it too, with user names, IP addresses and times.
List recently changed files
A quick list of PHP files changed in the last two weeks often points straight at the problem. It is read-only, so it is safe to run now:
find . -type f -name '*.php' -mtime -14 -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r | head -50
find wp-content/uploads -type f -name '*.php'Attackers can fake file times, so treat this as a lead, not proof. Any PHP file inside uploads is almost always malicious, because WordPress never puts PHP there.
05Minutes 25 to 40: reset every credential
Assume every password that touched the site is known to the attacker. Reset them in this order, starting with the accounts that control everything else. Do it from a clean device. If your own computer is infected, new passwords leak again, so scan it too.
| Credential | Where | Often missed? |
|---|---|---|
| Hosting account and control panel | Host dashboard; turn on two-factor login | No |
| SFTP, FTP and SSH users, plus SSH keys | Host panel; remove keys you do not recognize | Yes, keys and old FTP users |
| Database user password | Host panel, then update DB_PASSWORD in wp-config.php | Yes |
| WordPress admin accounts | Users; delete unknown admins after you record them | No |
| All other WordPress users | Force password resets | Yes |
| Salts and keys | wp-config.php, logs everyone out | Yes |
| Application passwords | Users → Profile → Application Passwords | Almost always |
| API keys and tokens | SMTP, payment gateway, Cloudflare, CDN, backup storage | Yes |
| Email accounts on the domain | Email provider | Yes, used for password resets |
Find rogue admin accounts
Attackers like to add an admin with a believable name, such as wpadmin or support. List every administrator with the registration date:
wp user list --role=administrator --fields=ID,user_login,user_email,user_registeredRecord anything unknown in your notes before you delete it. Deleting a user is permanent, and WordPress asks what to do with their content, so assign it to a real user.
Rotate salts to end every session
Changing passwords does not log out an attacker who already has a valid login cookie. New salts do. The WordPress.org FAQ says that replacing the keys in wp-config.php forces anyone still logged in off. Generate new values from the WordPress.org salt generator, or with WP-CLI:
wp config shuffle-saltsOne caveat: a few plugins use the salts to encrypt stored settings, and rotating them can mean re-entering an API key in that plugin. That is a small price after a hack.
Revoke application passwords
Application passwords let tools log in through the REST API without the normal password. They survive a password change. The WordPress application passwords guide says you can review them, with last used time and IP, under Users → Profile, and revoke them there. Check every admin account. With WP-CLI:
wp user application-password list 1 --fields=uuid,name,created,last_used,last_ip
wp user application-password delete 1 <uuid>An application password you did not create, especially one used from an unfamiliar IP, is a strong clue to how the attacker kept access.
06Minutes 40 to 60: talk to the host and decide the recovery path
Questions to ask the host
- Do you see malware on the account, and which files did your scanner flag?
- Are other sites on the same account infected? On shared hosting, one hacked site can reach every other site under the same user.
- Do you have a clean backup, and from which dates?
- Can you send the raw access logs for the last 30 days?
- Is the account suspended or limited, and what do you need to lift it?
If the account is already suspended, our account suspended fix covers what hosts usually ask for.
Clean, restore or rebuild?
| Path | Choose it when | Risk |
|---|---|---|
| Restore a backup | You know when the hack started and have a backup from before it, and little content changed since | The hole is still open; you must still patch and reset |
| Clean in place | Small, recent infection, clear entry point, good file and database visibility | Missing one backdoor means reinfection |
| Rebuild from known-good sources | Unknown start date, many infected files, or repeated reinfection | More work, but the most reliable |
Backups are often less clean than they look. Attackers frequently sit on a site for weeks before acting, so the backup from yesterday may hold the same backdoor. Use your logs and the file list to estimate when the first malicious file appeared, and pick a backup from before that date.
07After the first hour: clean the site properly
The rebuild method below is what we use when the start date is unclear. It replaces everything that can be replaced from an official source, and only keeps what cannot: uploads, the database and your own custom code, each checked by hand.
1. Replace WordPress core
First check which core files were changed. The core verify-checksums command compares every core file against the official checksums for your version:
wp core verify-checksums
wp core verify-checksums --include-rootThen replace wp-admin and wp-includes completely with fresh copies of the same version. The WordPress.org FAQ recommends doing this over SFTP rather than through the dashboard reinstall, because the dashboard itself may be compromised.
2. Replace plugins and themes
Delete every plugin and theme folder and install fresh copies from WordPress.org or the vendor. Do not copy them over the old folders, because extra malicious files would survive. For plugins from the WordPress.org directory, the plugin verify-checksums command flags modified files first:
wp plugin verify-checksums --allPremium plugins are not in the WordPress.org directory, so download them again from the vendor account. Remove any plugin you do not use, and never install nulled premium plugins; they are a common source of backdoors.
3. Check the places scanners miss
wp-content/mu-plugins: must-use plugins load on every request and do not appear in the normal plugin list. Know what belongs there..htaccessfiles in the root and subfolders: look for redirect rules aimed at search engine or mobile visitors..user.iniandphp.ini: anauto_prepend_fileline loads a file before WordPress. Wordfence uses this on purpose for its firewall, so check what it points to rather than deleting it blindly.wp-config.php: compare it with a freshwp-config-sample.php; extraincludelines or long encoded strings are red flags.- Uploads: remove any PHP file, then check the folder again after a day.
- Scheduled tasks, both WP-Cron and the host's cron jobs in the control panel.
ls -la wp-content/mu-plugins
grep -rn 'auto_prepend_file' --include='*.ini' --include='.htaccess' .
wp cron event list --fields=hook,next_run_relative,recurrence4. Clean the database
Many hacks live in the database, not in files: script tags injected into posts, redirect code in options, or widget content. Search before you change anything:
SELECT ID, post_title FROM wp_posts WHERE post_content LIKE '%<script%' OR post_content LIKE '%eval(%';
SELECT option_name FROM wp_options WHERE option_value LIKE '%<script%' OR option_value LIKE '%base64_decode%';Adjust the wp_ prefix to match yours. Some results will be legitimate, such as an analytics snippet you added on purpose, so check each one before you edit it.
5. Scan again, then bring the site back
Run a server-side scanner such as Wordfence and an outside check such as Sucuri SiteCheck. Load the site from a private window and from mobile data. Only then remove the maintenance page, and watch the logs closely for the next few days.
08Harden it so it does not happen again
Cleaning without fixing the entry point is how sites get reinfected within a week. Match the hardening to what your logs showed, then add the basics.
| Likely entry point | Fix |
|---|---|
| Outdated or vulnerable plugin | Update or remove it; set up a regular update routine |
| Stolen or weak password | Unique passwords, two-factor login for every admin, login rate limits |
| Nulled theme or plugin | Replace with the licensed version or an alternative |
| Another site on the same account | Clean every site, separate accounts or users per site |
| Leaked application password or API key | Revoke, and limit who can create them |
| Unknown | Rebuild, harden everything, and monitor file changes |
From the WordPress.org hardening guide: turn off the built-in file editor, and set folders to 755 and files to 644. The guide suggests 400 or 440 for wp-config.php where your host allows it.
define( 'DISALLOW_FILE_EDIT', true );The guide is clear that this stops someone editing files from the dashboard but does not stop an attacker uploading files. To stop PHP running in uploads, ask your host for the right rule for your server. An Apache php_flag line does not work on PHP-FPM, LiteSpeed or Nginx setups, which is why snippets copied from old guides often do nothing.
Add a firewall (a plugin, the host's, or Cloudflare), daily off-site backups kept for at least 30 days, and uptime and file change monitoring. A good maintenance plan covers all of this as routine work rather than a one-off.
Once the site is clean, keep the same gaps from reopening with a monthly review. Our monthly WordPress security checklist covers users, application passwords, backups, files, DNS and the client report.
09Get Google and browser warnings removed
If Google flagged the site, warnings stay until you ask for a review. Do not request one until the site is fully clean; a failed review slows things down.
- Verify the site in Google Search Console if it is not already.
- Open the Security issues report and read which issue types and sample URLs Google lists.
- Check those URLs yourself with a plain request, such as
curl -A Googlebot, to see what Google sees. Some hacks show spam only to Googlebot. - Make sure Google can crawl the cleaned pages: no robots block, no noindex, no maintenance page.
- Click Request Review and describe what you removed and how you fixed the entry point.
How long it takes depends on the issue. According to Google's review request guide, hacked spam reviews can take up to several weeks, malware a few days, and phishing about a day. If the review finds the site clean, warnings are removed within 72 hours. Google's Security issues report help asks you not to resubmit before you get a decision.
Spam pages created by a hack (the Japanese keyword hack is the classic case) can stay in search results for a while after removal. Make sure they now return 404 or 410, and use the Removals tool in Search Console for the worst ones.
10Tell the client, and know when the law applies
For agencies, how you communicate decides whether you keep the client. Tell them early, tell them what you know and do not know, and give them a time for the next update. A short message works: what happened, what you have done to protect visitors, what happens next, and when they will hear from you again. Avoid guessing at the cause on day one.
After the cleanup, send a short incident report: timeline, entry point (or best estimate), what was cleaned, what was changed, and what will stop it happening again. This report is also where the recurring work comes from: the hardening and monitoring in it are a care plan.
Personal data and GDPR
If the site holds personal data (form entries, customer accounts, orders) and serves people in the EU or UK, a hack can be a personal data breach. Under GDPR Article 33, the controller (usually the client, not the agency) must notify the supervisory authority without undue delay and, where feasible, within 72 hours of becoming aware of it, unless the breach is unlikely to result in a risk to people. A processor, which is often what the agency is, must tell the controller without undue delay. Where the risk to people is high, Article 34 requires telling the affected people too.
You are not the client's lawyer, and neither are we. The practical job for an agency is to tell the client quickly, give them the facts they need (what data, how many records, when), keep your notes, and point them to legal advice. Other countries and US states have their own breach rules.
If you manage many sites
- Check whether the hacked site shares an admin password, an SFTP user or a hosting account with other client sites. If so, treat them all as exposed.
- Scan every site on the same server or account, not just the one that showed symptoms.
- Rotate team passwords in your password manager and remove ex-staff and ex-freelancer access across all sites.
- Keep a one-page incident runbook, like the table at the top of this guide, so whoever is on call follows the same order.
11Common hack symptoms and what to check first
Visitors from Google or mobile are redirected to spam sites
Quick fix: Contain the site, back it up, then check every .htaccess file and search posts and options for injected scripts.
Why it happens: Conditional redirects target visitors who come from search engines or use phones, so the owner browsing while logged in sees nothing wrong.
- Test from a private window on mobile data, and with
curl -A Googlebot. - Look for
RewriteCondlines that check the referrer or user agent. - Search
wp_postsandwp_optionsfor<scriptandeval(. - Replace core, plugins and themes, then rotate salts and passwords.
Our hacked redirects fix has more detail on this one.
Google shows Japanese or spam pages for your domain
Quick fix: Find the PHP file generating the pages, remove it, make the spam URLs return 404 or 410, and request a review.
Why it happens: The attacker serves thousands of generated pages, usually only to Googlebot, and submits them through a sitemap. Sometimes they also add their own owner to your Search Console property.
- In Search Console, check Settings → Users and permissions and remove owners you do not know.
- List recently changed PHP files and any PHP in uploads.
- Remove injected sitemaps and check robots.txt.
- Rebuild, then request a review and use the Removals tool for the worst URLs.
Chrome shows a red warning before your site loads
Quick fix: Read the issue type in Search Console, clean the site fully, then click Request Review.
Why it happens: Google found malware, unwanted software or a phishing page on the site and shares that with browsers.
- Note the issue type and sample URLs in Search Console.
- Clean and verify those URLs.
- Request a review with a clear description.
- Allow a few days for malware and about a day for phishing.
Unknown admin users keep appearing
Quick fix: Find and remove the code that creates the user before deleting the user again.
Why it happens: Deleting the user treats the symptom. Hidden code runs on every page load or on a schedule and adds the account back.
- List admins with registration dates.
- Check
wp-content/mu-pluginsand the themefunctions.php. - List WP-Cron events and host cron jobs.
- Search for
wp_create_userandwp_insert_userin files outside core.
The site is reinfected days after cleaning
Quick fix: Stop cleaning in place and rebuild from official sources, then find the entry point in the logs.
Why it happens: Either a backdoor survived, a credential was not rotated, or another site on the same account is reinfecting this one.
- Note the exact time of reinfection and match it in the access logs.
- Check other sites on the same hosting account.
- Confirm every credential in the reset table was changed, including SSH keys and application passwords.
- Rebuild core, plugins and themes from fresh copies.
The host suspended the account for malware
Quick fix: Ask the host for the scan report and temporary access to clean, then send proof of cleanup.
Why it happens: Hosts suspend accounts to protect their servers and IP reputation.
- Request the flagged file list and logs.
- Back up the infected site for evidence.
- Clean or rebuild, then ask the host to rescan.
- Reset all hosting and SFTP credentials.
12Doing it yourself vs getting help
A small infection on a brochure site, with a clear cause and a clean backup, is a reasonable job for a confident site owner with this guide. Get help when the site is a store or holds customer data, when you cannot find the entry point, when it has been reinfected, or when it is a client site and your time is better spent on the client.
We handle hacked site cleanup with malware removal, hardening and the Google review, quoted within 24 hours. Smaller errors start from $59. For agencies, our white label care plans include security scans and malware cleanup, from $25 a site a month, so the next incident is caught early. All rates are on our pricing page.
Need the full list? See our WordPress errors fix guide and the hosting, PHP and cPanel errors guide.
Fixes for related errors
13FAQ
What is the first thing to do when a WordPress site is hacked?
Confirm it is a hack, then contain it with a maintenance page or by taking the site offline. Next back up the infected files, database and logs for evidence, and only then reset passwords and start cleaning.
Should I just restore a backup?
Only if the backup is from before the attacker got in. Attackers often sit on a site for weeks, so recent backups may contain the backdoor. Even after a restore you must patch the entry point and reset every credential.
Does changing my WordPress password remove the hacker?
No. An attacker with a valid login cookie, an application password, SFTP access or a backdoor file stays in. Rotate the salts, revoke application passwords, reset hosting and database passwords, and remove backdoors.
How do I remove the Google warning from my hacked site?
Clean the site fully, then open the Security issues report in Google Search Console and click Request Review. Google says phishing reviews take about a day, malware a few days and hacked spam up to several weeks.
How do I know how my WordPress site was hacked?
Read the server access logs around the time the first malicious file appeared, check for unknown admins and application passwords, and look for outdated plugins. That is why you save the logs before cleaning.
Can a security plugin clean a hacked site on its own?
It can find and remove a lot, but scanners miss database injections, host cron jobs and some backdoors. Use a scanner as one step, alongside replacing core, plugins and themes from official sources.
Do I have to report a hacked website under GDPR?
If personal data was affected and there is a risk to people, the controller must notify the supervisory authority within 72 hours where feasible. Agencies acting as processors must tell the client without undue delay. Get legal advice for your case.
How long does it take to clean a hacked WordPress site?
Containment and credential resets fit in the first hour. A full cleanup usually takes from a few hours to a day, depending on the size of the site and whether you clean, restore or rebuild. Google reviews add days to weeks.
SOURCES
- WordPress.org: FAQ My site was hacked
- WordPress Developer: Hardening WordPress
- WordPress Developer: Application passwords
- WP-CLI: wp core verify-checksums
- WP-CLI: wp plugin verify-checksums
- Google (web.dev): Request a review
- Google Search Console Help: Security issues report
- GDPR Article 33: Notification of a personal data breach






