1. Home
  2. Blog
  3. How to Recover a Hacked WordPress Site
  • Security
  • 10 min read

How to Recover a Hacked WordPress Site

WordPress websites have become a prime target for AI-powered polymorphic attacks. This guide explains how to clean a compromised site completely with modern techniques and make it resilient against future threats.

By meomanWordPress since 2008

First Response: Emergency Protocol After an Attack

The moment you notice your site has been hacked, every second counts in limiting the damage. The first step is always to restrict the site’s interaction with the outside world and freeze its current state.

  • Put the site into maintenance mode to stop visitor and bot traffic.
  • Change all FTP, control panel and database passwords immediately.
  • Take an isolated backup of the hacked site as it is now, so it can be analyzed.

After breaking into a site, attackers often plant time-triggered “logic bombs” in the database. That is why replacing files alone is not enough; you must also end all active sessions and regenerate the security keys (SALT keys) in the wp-config.php file. This invalidates every active cookie the attacker holds and blocks attempts to get back in.

To find the source of the attack, examine the server access logs and error logs in depth. Files receiving a concentration of POST requests in particular point to where the attacker uploaded a web shell. With 2026 technology, these logs can be analyzed automatically to report clearly which IP address exploited which vulnerability.

If your site is part of a server network, check whether other sites have been affected as well. Cross-site contamination is the most common cleanup mistake on shared servers. Cleaning one site is not a lasting solution as long as other sites in the same user directory remain infected.

Security layerPre-2026 methodModern approach (2026)ImpactImplementation effort
File checksManual FTP scanWP-CLI integrity checkVery highLow
MalwareSignature-based scanningBehavioral AI analysisHighMedium
Login securityComplex passwordsBiometric passkeys and MFACriticalLow
DatabaseManual SQL queriesAutomated injection cleanersHighHigh
MonitoringWeekly log checksReal-time SIEM integrationMediumHigh

Deep Cleaning the File System: Removing Malicious Code

Malware usually hides by embedding itself in legitimate WordPress files or imitating system files. Instead of cleaning by hand, replacing the core files with their original versions is the safest approach.

  • Deleting the wp-admin and wp-includes folders entirely and uploading them again from the official source.
  • Finding files in plugin and theme folders that contain code but do not have a .php extension.
  • Checking the .htaccess and index.php files in the root directory for tampering.

Using WP-CLI is the fastest way to verify WordPress core files. The wp core verify-checksums command compares the hash of every file on the system with the one in the official WordPress repository. If there is any mismatch, it immediately reports which file was modified. This method exposes even single-line eval(base64_decode(...)) injections that are impossible to spot by eye.

Themes and plugins are attackers’ favorite hiding places. Free themes known as “nulled” or pirated in particular come with built-in backdoors. During cleanup, deactivate all plugins and replace each one with a fresh copy downloaded from the official directory (wordpress.org). By current standards, no plugin that is not actively maintained should stay on the system.

Under normal conditions, the wp-content/uploads directory should contain no PHP files at all. Attackers can upload scripts disguised as image files there. When scanning this directory, check for files with .php, .phtml, .exe or .js extensions and delete any you find immediately. Adding an .htaccess rule that blocks PHP execution in this directory is also one of the most effective barriers against future attacks.

Database Security: Closing Hidden Backdoors

Even if the file system has been cleaned, a malicious admin user or a JavaScript redirect planted in the database will get the site hacked again. Cleaning the database requires careful work at the SQL level.

  • Search for and delete unauthorized administrator accounts in the wp_users table.
  • Confirm that the siteurl and home values in the wp_options table are correct.
  • Bulk-remove hidden <iframe> elements or external script links embedded in posts.

Increasingly common “database injections” are usually used to redirect users’ browsers to ad sites. This code is typically appended to the end of content in the wp_posts table. You can clean up this contamination with SQL queries such as UPDATE wp_posts SET post_content = REPLACE(post_content, 'malicious-code', '');. However, taking a full database backup before doing this prevents irreversible mistakes.

To hide themselves, attackers sometimes change an existing administrator’s email address or create a new “super admin” at the database level. Check the wp_usermeta table and review every user whose wp_capabilities value is administrator one by one. Every unrecognized profile is a potential backdoor and should be wiped from the system.

Database optimization is also part of the cleanup process. Reduce the database size by removing unnecessary transients, leftovers from old plugins and spam comments. A clean database is vital not only for security but also for load speed, which is one of the SEO criteria. Changing the database table prefix from the default wp_ to a complex value stops automated SQL injection bots to a large extent.

Related serviceWordPress Security Settings

5 Effective Security Plugins

Security plugins build a digital fortress around your site. These tools go beyond file scanning and work with cloud-based threat intelligence.

  • Wordfence Security: Real-time endpoint protection and an AI-assisted WAF.
  • Sucuri Security: Blocks DoS attacks with a cloud-based firewall and CDN integration.
  • Solid Security (formerly iThemes): Login security and file change monitoring.
  • MalCare: Cloud-based, one-click malware cleanup that does not strain the server.
  • All In One WP Security: A comprehensive firewall and database hardening tools.

Source: WordPress.org Plugin Directory

Among these plugins, Wordfence has the largest threat database. Its “Learning Mode” in particular learns your site’s normal traffic patterns and instantly blocks suspicious activity outside them. The plugin’s live traffic monitoring panel lets you see in real time which files attackers are targeting.

Sucuri, on the other hand, is ideal for professionals who want to reduce the load on their server. Traffic passes through Sucuri’s cloud servers before reaching your site, so malicious bots are filtered out before they ever touch your server. Against the growing number of brute-force attacks, this kind of cloud protection keeps server resources from being exhausted.

MalCare’s “Auto-Clean” feature analyzes complex code structures and can remove only the malicious part. This eliminates the risk of accidentally breaking the site during manual intervention. On complex e-commerce sites with many plugins in particular, MalCare’s deep scanning technology saves a great deal of time.

User Authorization and Access Control

The weakest link in the security chain is always people. Because passwords have become so easy to steal, access control should follow the “Zero Trust” principle.

  • Mandatory two-factor authentication (2FA) or passkeys for all users.
  • Renaming the wp-login.php page or restricting it by IP.
  • Reorganizing user roles according to the principle of least privilege.

Passwordless login technology (passkeys) has become standard in the WordPress ecosystem. It lets users log in with biometric data on their device (fingerprint, face recognition). This removes the risk of losing passwords to phishing attacks. Enabling this feature for every administrator account takes your site’s security to the next level.

Limiting login attempts (login throttling) slows down how fast bots can try passwords. If an IP address exceeds a certain number of failed logins, that IP should be banned permanently at the server level (with iptables or a WAF). Allowing wp-admin access only from certain countries or IP addresses also shrinks the global attack surface by 90%.

Auditing user accounts regularly and deleting old employee or author accounts that are no longer used is critical for security hygiene. Automated permission management systems can suspend the rights of accounts that have been inactive for a certain period. Such automation is very effective in preventing break-ins through forgotten accounts.

Server-Level Hardening

WordPress security does not start only at the application level but also at the level of the server it runs on. A flaw in the server configuration can neutralize even the most capable security plugin.

  • Always keeping PHP on the latest version (PHP 8.4+).
  • Disabling dangerous PHP functions (exec, system, passthru) with the disable_functions directive.
  • Setting file permissions to 755 and assigning file ownership to the correct user.

Server-side web application firewalls (WAFs) can now analyze traffic arriving over HTTP/3. Custom rules added to Nginx or Apache configuration files can stop common WordPress exploits before they reach the application layer. For example, disabling the XML-RPC protocol completely eliminates pingback attacks and brute-force attempts at the root.

Review file system write permissions again after the cleanup. Set the permissions of critical files such as wp-config.php to 400 or 440 so that not even the web server can modify them. This simple measure makes it impossible for an attacker who gets in through a vulnerability to tamper with the configuration file.

SSL certificates are now used not only to encrypt data but also to verify a site’s identity. HSTS (HTTP Strict Transport Security) forces browsers to communicate with the site only over a secure connection. This is a mandatory step for preventing man-in-the-middle attacks.

Reputation and SEO Recovery After the Cleanup

Cleaning a site is a technical achievement, but removing the “This site may harm your computer” warning in search engines is a PR and SEO process.

  • Check the “Security Issues” report in Google Search Console and submit a review request.
  • Contact the relevant authorities to have blacklisted IP addresses and domains cleared.
  • Remove the thousands of fake (Japanese or spam) pages created during the attack from the index.

In its 2026 algorithms, Google is more cautious toward sites that have suffered a security breach. After the cleanup, update the sitemap.xml file so Google’s bots recrawl the site, and request indexing of critical pages manually with the “URL Inspection” tool. If attackers added thousands of spam pages to your site, make sure those pages return 404 Not Found or 410 Gone.

To win back your SEO reputation, you may need to use a disavow file for harmful backlinks pointing to your site. Thousands of low-quality links pointed at your site during the attack can hurt your search rankings. SEO tools can detect such toxic links automatically and report them to Google.

Finally, be transparent with your users. If there is any suspicion that user data was leaked, you are legally required to notify the people affected and the authorities (under GDPR, and Turkey’s KVKK where relevant). Data transparency is the strongest way to build brand loyalty. Explaining how you closed the vulnerability and what measures you have taken will rebuild the trust that was shaken.

Frequently Asked Questions

1. What should I do first when my site is hacked?

Put your site into maintenance mode right away, change all FTP/panel passwords and create a backup of the current state. This stops the attacker from doing more damage and preserves evidence for analysis.

2. Is it enough to delete all files and restore a backup?

No, because the attacker may have left a backdoor in the database, or your backup may already be infected. Run every file through a core integrity check and scan the database manually.

3. When will the “Dangerous site” warning on Google disappear?

Once you submit a review request through Google Search Console after the cleanup, the process usually takes 24 to 72 hours. The warning is removed automatically once Google’s bots confirm the site is clean.

4. Are free security plugins enough?

Free plugins provide basic protection against complex attacks, but premium solutions are more effective for a real-time WAF and cloud-based scanning. For high-traffic sites in particular, pro versions are hard to do without.

5. What should I watch out for when cleaning the database?

Pay particular attention to the wp_users and wp_options tables and delete any administrator accounts you do not recognize. Always take an SQL backup before making changes to minimize the risk of data loss.

In summary
WordPress security requires a proactive approach: recovering a hacked site is not just about deleting files but about cleaning every layer, from the database to the server, with AI-assisted tools. With the right strategy and modern tools, you can minimize the loss of reputation after an attack and make your site more secure than before.