EN · $ USD
WordPress and E-commerce

How to Clean Up a Hacked WordPress Site

7 min read Updated: Sunucu Atlas technical team

In short

To clean a hacked WordPress site, put it in maintenance mode and take a full backup first. Then replace wp-admin and wp-includes with the official WordPress package, reinstall plugins and themes from clean copies, and delete PHP files in uploads and injected code in the database. Finally, reset all passwords and security keys and request a review in Google Search Console.

In this guide
  1. Signs Your Site Has Been Hacked
  2. Step 1: Isolate the Site and Back Up the Evidence
  3. Step 2: Find the Malicious Code
  4. Step 3: Replace Core Files, Plugins and Themes
  5. Step 4: Clean the Database
  6. Check Hidden Persistence Points
  7. Step 5: Reset Users, Passwords and Keys
  8. Step 6: Close the Entry Point
  9. Step 7: Get Off the Google Blocklist
  10. Starting Over on Clean Infrastructure
  11. Next Step

If your WordPress site has been hacked, don't panic. Follow an order: stop the damage, back up the evidence, clean up, then close the door. Cleanup means finding the malicious code, replacing core files from the official package, swapping plugins and themes for clean copies, scanning the database, resetting every password and security key, and asking Google to remove the blocklist warning. The steps below follow the order a sysadmin uses during incident response.

Signs Your Site Has Been Hacked

Attackers usually work quietly. If you see any of these signs, treat the site as compromised:

  • Visitors coming from mobile or Google search are redirected to gambling, pharma or fake store sites.
  • Google search results show pages with Japanese or unrelated keywords (SEO spam).
  • Browsers show a "Deceptive site" warning, or Search Console reports Security issues.
  • There are users you don't recognize in the administrator list.
  • You got a warning that your hosting account sent bulk spam, or CPU usage is unexplainably high.
  • Files ending in .php show up inside wp-content/uploads, or randomly named files appear in the root directory.

Step 1: Isolate the Site and Back Up the Evidence

The first job is to stop the damage from spreading. Put the site in maintenance mode, or temporarily use an .htaccess rule to allow only your own IP address. Then, before you clean anything, take a full backup of the site in its infected state: files and database. You need this backup to restore anything deleted by mistake and to investigate how the attacker got in. For backup steps, see the cPanel backup and restore guide.

If you have a clean backup from before the hack and losing the content added since then is acceptable, restoring that backup is the fastest fix. But if the entry point stays open, the site will be hacked again within days, so always complete steps 5 and 6.

Step 2: Find the Malicious Code

If your account has SSH access, detection is much faster. WP-CLI can compare core and plugin files against the official checksums published on WordPress.org:

cd ~/public_html
wp core verify-checksums
wp plugin verify-checksums --all

Every modified or extra file is listed. Next, look for PHP files changed in the last few days and for common obfuscation patterns:

# PHP files changed in the last 7 days
find . -name '*.php' -mtime -7 -type f

# PHP files that should not be in the uploads folder
find wp-content/uploads -name '*.php' -type f

# Suspicious function patterns
grep -rlE 'eval\(base64_decode|gzinflate\(base64_decode|str_rot13\(|assert\(\$_' --include='*.php' .

Without SSH, you can sort files by the Last Modified column in cPanel File Manager and run the same checks by hand. Files that receive a burst of POST requests in the access logs are often the backdoor itself; the cPanel access and error logs guide makes reading logs easier.

Step 3: Replace Core Files, Plugins and Themes

Rather than hunting for malicious lines one by one, it is safer to replace everything that may have been modified with a clean copy.

  1. Core: Delete the wp-admin and wp-includes folders completely and replace them with the same version downloaded from WordPress.org. Also replace the wp-*.php and index.php files in the root directory. With WP-CLI: wp core download --force --skip-content
  2. wp-config.php: Don't delete this file; open it and review the lines at the very top and bottom. Remove any include, eval or long encoded strings you don't recognize.
  3. Plugins: Make a list of the plugins you use, empty the wp-content/plugins folder and reinstall each one from its official source. Unlicensed (nulled) themes and plugins are the most common source of infection; never put them back.
  4. Themes: Reinstall your active theme from the original package and check the child theme's functions.php line by line. Delete themes you don't use.
  5. uploads: This folder should contain only media. Delete every .php, .phtml and suspicious hidden file (starting with .) you find.

Step 4: Clean the Database

Redirect and SEO spam attacks are usually written into the database too. Check these points in phpMyAdmin:

  • In the wp_options table, do siteurl and home point to the correct domain?
  • In the wp_posts table, are there posts containing <script or <iframe?
  • In the wp_users table, are there accounts you don't recognize?

A sample query to find suspicious content (change the wp_ part if your table prefix is different):

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 '%base64_decode%';

Always export the database before changing it; you can use the Export tab in phpMyAdmin.

Check Hidden Persistence Points

Experienced attackers use lesser-known WordPress loading points so they can come back after a cleanup. Review each of these locations:

  • wp-content/mu-plugins: Files here load automatically on every request as "must-use plugins" and don't appear in the normal plugin list in the dashboard. Unless you put something there on purpose, this folder should be empty.
  • Drop-in files: advanced-cache.php, object-cache.php and db.php inside wp-content should exist only if you use a caching plugin.
  • .htaccess files: Check the .htaccess files in the root and in subfolders for a RewriteRule to unfamiliar domains or an auto_prepend_file line.
  • Cron jobs: An unfamiliar command in the cPanel Cron Jobs list may be re-downloading the deleted malware at regular intervals.
  • Outside the web root: The home directory above public_html should not contain randomly named PHP files either.

Step 5: Reset Users, Passwords and Keys

If the attacker stole a password, cleaning the files alone is not enough. Work in this order:

  1. Delete administrator accounts you don't recognize and reassign their content to your own account.
  2. Change every administrator and editor password to a strong, unique password.
  3. Regenerate the security keys (salts) in wp-config.php; this logs out every active session.
  4. Change your cPanel password, FTP account passwords and the database user's password. After changing the database password, remember to update the DB_PASSWORD value in wp-config.php.
wp user list --role=administrator
wp user delete SUPHELI_KULLANICI --reassign=1
wp config shuffle-salts

Finally, if spam was sent through the site, change your email account passwords as well.

Step 6: Close the Entry Point

A cleanup only sticks once you find how the attacker got in. The most common entry points are:

Entry pointHow to spot itPermanent fix
Outdated plugin or themeOld version with a known vulnerabilityAutomatic updates, delete unused ones
Nulled (pirated) theme/pluginPackage with the license check removedInstall only from official sources
Weak or leaked passwordHeavy POST traffic to wp-login.php in the logsStrong password, two-factor authentication
Another site in the same accountMalicious files in other folders tooClean all sites together

The last row matters: an old, unmaintained site in the same hosting account will reinfect the site you just cleaned. We collected the long-term hardening steps in WordPress security: 12 settings that prevent hacks.

Step 7: Get Off the Google Blocklist

Google's warning doesn't disappear on its own right after cleanup. Follow these steps:

  1. Verify your site in Google Search Console (if you haven't already).
  2. Open the Security & Manual Actions > Security issues report and confirm the sample URLs listed are now clean.
  3. Click Request Review; in the description, briefly and specifically explain what you found, what you deleted and which hole you closed.
  4. If SEO spam pages were created, make sure those URLs return 404 or 410; if needed, hide them temporarily with the Removals tool.

Review time is up to Google; the result is reported in Search Console. If the request is rejected, a malicious file usually slipped through; go back to step 2.

Starting Over on Clean Infrastructure

Sometimes the healthiest option is to set up the cleaned content on a new, clean hosting account. Our WordPress hosting plans come with one-click installs through WP Toolkit, LiteSpeed Web Server and a free SSL certificate, so you can install WordPress fresh from the official source and move only your cleaned content. If you keep more than one site in the same account, the SA-WP-3 plan, with a 2-site limit (addon domains), 3 GB RAM and a 10-subdomain limit, gives you room to manage your main site and a test copy separately.

Next Step

After cleanup, check your logs and changed files regularly for two weeks; reinfection usually shows up within that window. If you decide to move to new infrastructure, compare WordPress hosting options, do a clean install and migrate your content. If you get stuck during migration or setup, you can reach the Sunucu Atlas support team through a support ticket (support is provided in Turkish).

Frequently asked questions

My WordPress site was hacked. What should I do first?

Put the site in maintenance mode or block access, then take a full backup of the infected files and database before you start cleaning. After that, change all administrator, cPanel and FTP passwords.

Is installing a security plugin enough to clean a hacked site?

Usually not. Scanner plugins find known patterns but can miss code written into the database, backdoors and the original entry point. Replacing core and plugin files with clean copies is more reliable.

Why does my site get hacked again after cleanup?

The most common reason is that the entry point was never closed: an outdated plugin, a nulled theme, a password that wasn't changed or another unmaintained site in the same account. Until those are fixed, a cleanup won't last.

How do I remove Google's 'This site may be hacked' warning?

Once the site is fully clean, submit a request with the Request Review button in the Security issues report in Google Search Console. When the request is approved, the warning is removed from search results.

Is restoring a backup from before the hack enough?

If the backup is truly clean, it is the fastest route. But the attacker's entry point is still there, so you also need to reset passwords and security keys and update your plugins.

For this guide

Recommended plans

Move your cleaned content to a fresh WordPress hosting account with one-click WP Toolkit installs, LiteSpeed and free SSL, and relaunch your site on solid, secure ground.

SA-WP-1

cPanel
Recommended

20 GB NVMe disk

$0.39/mo

+VAT

  • Processor1 cores
  • Memory1 GB
  • LocationIstanbul
  • WordPress One-Click Install (WP Toolkit)
  • 1 Hosted Domains
  • 50 GB Traffic
  • 5 Email Account Limit

SA-WP-2

cPanel

40 GB NVMe disk

$0.69/mo

+VAT

  • Processor2 cores
  • Memory2 GB
  • LocationIstanbul
  • WordPress One-Click Install (WP Toolkit)
  • 1 Hosted Domains
  • 100 GB Traffic
  • 10 Email Account Limit

SA-WP-3

cPanel

60 GB NVMe disk

$0.98/mo

+VAT

  • Processor3 cores
  • Memory3 GB
  • LocationIstanbul
  • WordPress One-Click Install (WP Toolkit)
  • 1 Hosted Domains
  • 200 GB Traffic
  • 25 Email Account Limit

WordPress Hosting — tüm paketler

Need help with setup?

Send questions about your service in a support ticket, and our technical team will walk you through it step by step.