WordPress hacked: what to do and how to remove malware

Work in the right order: preserve and contain, then clean, then close the entry point. Deleting files in a panic often destroys the evidence that shows how the attacker got in.

WordPress hacked: the first 30 minutes

When your WordPress site is hacked, the first job is to stop the damage and preserve the current state. In this order:

  1. Tell your host: Most hosts have a process for compromised accounts and can see server logs you cannot.
  2. Take a full snapshot: Files and database exactly as they are now. This copy is for analysis, not for restoring.
  3. Take the site offline or block access: A server-level maintenance page protects visitors from malicious redirects and scripts.
  4. Change every password: WordPress admins, hosting account, SFTP/SSH, database, and the admin's email account. Use a device you trust.
  5. Rotate the salts: New keys in wp-config.php kill every active session, including the attacker's.
wp db export incident-$(date +%F).sql
tar czf incident-files-$(date +%F).tar.gz /path/to/wordpress
wp config shuffle-salts

Find out what was changed

You cannot remove malware you have not located. WP-CLI has built-in integrity checks:

  • wp core verify-checksums compares every core file with the official checksums and flags modified or extra files.
  • wp plugin verify-checksums --all does the same for plugins from the WordPress.org directory. Commercial plugins cannot be checked this way.
  • wp user list --role=administrator reveals administrators you did not create.
  • List recently modified PHP files: find . -name "*.php" -mtime -14
  • PHP files in the uploads folder are almost always malicious: find wp-content/uploads -name "*.php"

Scanners such as Wordfence or the free Sucuri SiteCheck add pattern-based detection. No scanner catches every backdoor, especially newer ones, so treat a clean scan as a hint, not proof.

Remove malware from WordPress

Replace rather than repair wherever you can:

  1. Reinstall core: wp core download --force --skip-content overwrites wp-admin and wp-includes with clean files. Then delete anything in the web root that does not belong to WordPress.
  2. Reinstall plugins and themes: Delete each one and install a fresh copy from WordPress.org or the vendor instead of cleaning individual files. Remove anything you do not recognize.
  3. Check wp-config.php: Compare it with a clean template. Injected code often sits at the very top or bottom.
  4. Clean uploads: Delete PHP files and unknown scripts from wp-content/uploads, then block PHP execution in that folder at the web server.
  5. Inspect the database: Look at siteurl, home and active_plugins in wp_options, and for injected scripts and links in wp_posts. wp db search "<script" --all-tables is a quick start.
  6. Delete unknown users and reassign their content to a real account.

If the infection is widespread and you have a backup that provably predates it, restoring is often faster and safer than cleaning. Re-add any content created since then by hand.

What the infection tells you

The symptom usually points to where the code lives:

  • Redirects: Visitors from Google or on mobile land on another site, while you, logged in as admin, see nothing. Look in .htaccess, theme files and scripts stored in the database.
  • SEO spam: Thousands of injected pages advertising pharmacy, gambling or counterfeit goods, often shown only to search engines. A Google search for site:yourdomain.com exposes them.
  • Backdoors: Small PHP files that let the attacker return at will, often with harmless-looking names in wp-includes or uploads.
  • Hidden admins: Accounts with bland names, sometimes hidden from the Users screen by injected code. WP-CLI still lists them.
  • Outbound spam: Scripts that send bulk email through your server. Complaints from your host or suspended mail accounts are the giveaway.

Close the entry point

A cleanup without a root cause is temporary. Check these, most likely first:

Possible causeWhere to look
Vulnerable plugin or themeCompare installed versions with WPScan, Patchstack or Wordfence Intelligence
Stolen admin passwordSecurity plugin login logs, access logs for wp-login.php
Compromised hosting or FTP accountHost logs, timestamps of the first modified files
Another site on the same accountScan every installation in the same hosting space
Nulled premium pluginConfirm where every commercial plugin and theme came from

Web server access logs around the time of the first modified file often show the exact request that started the attack. Ask your host for them if you do not have access.

After the cleanup

  • Google warnings: If the site was flagged, open Security Issues in Search Console and request a review once it is clean.
  • Spam URLs in the index: Injected pages should return 404 or 410. Search Console's removal tool speeds things up.
  • Email reputation: If the site sent spam, check whether your domain or server IP landed on a blocklist.
  • Personal data: Work out whether customer data was exposed and whether you have notification duties.
  • Hardening: Apply the steps in WordPress security and set up off-site backups.

Keep watching for a few weeks. A second scan after several days, plus a look at new admin accounts and recently changed files, shows whether a backdoor was missed.

Common mistakes

  • Removing the visible redirect and leaving the backdoor in place.
  • Changing passwords on a computer that may itself be infected.
  • Restoring a backup that already contains the malicious code.
  • Reinstalling the same vulnerable plugin version after cleaning.

How eCloud Systems can help

Cleanup, root-cause analysis and follow-up maintenance are available on request. Use the contact form to describe what you see and what hosting access you have. If the old installation is too tangled to trust, a clean rebuild with our WordPress package can be the better route.

Frequently asked questions

How do I know my WordPress site was hacked?

Common signs are redirects to unknown sites, admin accounts you did not create, spam pages in Google results, browser or Search Console warnings, a sudden spike in server load or a notice from your host.

Can I just restore a backup?

Only if the backup was made before the compromise and you close the vulnerability afterward. Otherwise the site is reinfected quickly because the hole is still open.

Do I have to report a hack?

If personal data may be affected, such as customer accounts, orders or form submissions, data protection law may require notifying a regulator or the people affected. Under the GDPR the deadline is 72 hours. Check your situation with a lawyer; this is not legal advice.

Need a new WordPress website for a fixed price?

Up to 5 pages, mobile-ready, SEO basics, live in about 10 working days: €500 one-time, with a 30-day money-back guarantee. For help with an existing site, get in touch.