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
- Signs Your Site Has Been Hacked
- Step 1: Isolate the Site and Back Up the Evidence
- Step 2: Find the Malicious Code
- Step 3: Replace Core Files, Plugins and Themes
- Step 4: Clean the Database
- Check Hidden Persistence Points
- Step 5: Reset Users, Passwords and Keys
- Step 6: Close the Entry Point
- Step 7: Get Off the Google Blocklist
- Starting Over on Clean Infrastructure
- 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
.phpshow up insidewp-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.
- Core: Delete the
wp-adminandwp-includesfolders completely and replace them with the same version downloaded from WordPress.org. Also replace thewp-*.phpandindex.phpfiles in the root directory. With WP-CLI:wp core download --force --skip-content - wp-config.php: Don't delete this file; open it and review the lines at the very top and bottom. Remove any
include,evalor long encoded strings you don't recognize. - Plugins: Make a list of the plugins you use, empty the
wp-content/pluginsfolder and reinstall each one from its official source. Unlicensed (nulled) themes and plugins are the most common source of infection; never put them back. - Themes: Reinstall your active theme from the original package and check the child theme's
functions.phpline by line. Delete themes you don't use. - uploads: This folder should contain only media. Delete every
.php,.phtmland 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_optionstable, dositeurlandhomepoint to the correct domain? - In the
wp_poststable, are there posts containing<scriptor<iframe? - In the
wp_userstable, 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.phpanddb.phpinsidewp-contentshould exist only if you use a caching plugin. - .htaccess files: Check the
.htaccessfiles in the root and in subfolders for aRewriteRuleto unfamiliar domains or anauto_prepend_fileline. - 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_htmlshould 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:
- Delete administrator accounts you don't recognize and reassign their content to your own account.
- Change every administrator and editor password to a strong, unique password.
- Regenerate the security keys (salts) in
wp-config.php; this logs out every active session. - Change your cPanel password, FTP account passwords and the database user's password. After changing the database password, remember to update the
DB_PASSWORDvalue inwp-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 point | How to spot it | Permanent fix |
|---|---|---|
| Outdated plugin or theme | Old version with a known vulnerability | Automatic updates, delete unused ones |
| Nulled (pirated) theme/plugin | Package with the license check removed | Install only from official sources |
| Weak or leaked password | Heavy POST traffic to wp-login.php in the logs | Strong password, two-factor authentication |
| Another site in the same account | Malicious files in other folders too | Clean 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:
- Verify your site in Google Search Console (if you haven't already).
- Open the Security & Manual Actions > Security issues report and confirm the sample URLs listed are now clean.
- Click Request Review; in the description, briefly and specifically explain what you found, what you deleted and which hole you closed.
- 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.