Security

My WordPress site was hacked: what to do first

Almost every hacked WordPress site can be recovered. The order you do things in decides whether the attacker comes back.

A worried man holding his head in front of his computer
Share
In this article
  1. Signs your site was hacked
  2. 1. The first hour: lock them out
  3. 2. Find what they changed
  4. 3. Clean, or replace with clean copies
  5. 4. Close the door
  6. 5. Ask Google to remove the warning
  7. 6. Watch it for a few weeks

If your WordPress site was hacked, first lock the attacker out: change every password and remove any admin account you do not recognize. Then find what they changed, clean or replace it, close the way they came in, and ask Google to review the site if it shows a warning. Change the passwords before you clean anything: if you clean first, the attacker can log back in the next day and undo it.

Signs your site was hacked

  • Visitors are sent to spam, pharmacy or betting sites, sometimes only on mobile or only when they arrive from Google.
  • The browser shows a red warning before your site loads, or Google shows "This site may be hacked" under your result.
  • Search results for your site show pages you never wrote, often in another language.
  • There are admin users, plugins or files you did not add.
  • Your host suspended the account or emailed you about malware or spam being sent.

Some hacks are hidden from logged-in users, so check from a private window and from your phone, not only from your usual browser.

1. The first hour: lock them out

  • Take a copy of the site as it is now, files and database, and keep it apart from your clean backups, so you can compare it later and see exactly what was changed.
  • Change every password: the hosting account, SFTP, the database, and every WordPress administrator. Use your host's panel for the first three, since the attacker may be watching wp-admin.
  • Review the users. In Users, filter by Administrator and delete any account nobody on your team created. Check the email addresses too: attackers like names that look like a developer or the hosting company.
  • Log everyone out by changing the security keys (salts) in wp-config.php. You can generate new ones at api.wordpress.org/secret-key/1.1/salt/.
A password field filled with dots

2. Find what they changed

Look in the places attackers like to hide things:

  • The plugin list. In two cleanups we did this fall, the way in was the same: a plugin with a believable name that nobody had installed, and an admin account nobody had created.
  • wp-content/mu-plugins/, which runs code without showing up in the normal plugin list.
  • wp-config.php, .htaccess and the theme's functions.php, for code that loads something from another site or redirects visitors.
  • wp-content/uploads/, which should only hold media: a .php file in there is a red flag.
  • Files changed recently. Your host's file manager or a security plugin such as Wordfence or Sucuri can list them and compare core files with the originals.
A team talking in an office with code on the screens behind them

3. Clean, or replace with clean copies

Do not try to clean WordPress core files one by one. Reinstall them, and reinstall each plugin and theme from its official source, so every file is the original. Your own content lives in the database and in uploads, so those are what you clean by hand: remove suspicious files in uploads and look for injected scripts or spam links in posts, pages and widgets.

You can also restore a backup, but only if you know it is from before the hack. Many sites were infected weeks before anyone noticed, and restoring a backup from that time brings the problem back. Either way, the passwords from step 1 must change again after the restore.

4. Close the door

  • Update WordPress, every plugin and the theme.
  • Delete plugins and themes you do not use, and anything downloaded from an unofficial or "nulled" site.
  • Turn on two-factor authentication for every administrator.
  • Give each person only the role they need: an editor does not need to be an administrator.
  • Disable the file editor in the dashboard by adding define( 'DISALLOW_FILE_EDIT', true ); to wp-config.php.
A person holding a phone with a security login app open

5. Ask Google to remove the warning

If Google flagged the site, open Search Console, go to Security issues, confirm the problems are fixed and request a review. Reviews usually take from a day to a few days. Ask only when the site is really clean: a review that fails makes the next one take longer.

6. Watch it for a few weeks

For the next weeks, check the user list and the plugin list now and then, keep an eye on the file changes your security plugin reports, and search Google for site:yourdomain.com to spot spam pages. A hack that comes back within days usually means the way in is still open, or a hidden file was missed.

Frequently asked questions

Do I have to rebuild my site after a hack?

Almost never. Replacing WordPress, plugins and theme with clean copies and cleaning the database and uploads is enough in most cases. A rebuild only makes sense if the site was already due for one.

How did they get in?

The most common ways are an outdated plugin with a known vulnerability, a stolen or reused password, and plugins or themes downloaded from unofficial sites. The changed files and new users you find in step 2 usually point to the one used.

How long does Google take to remove the warning?

Once you request a review in Search Console, usually from one to a few days. The review only passes if the site is fully clean.

We can clean it up.

Tell us what you are seeing. We will clean the site and find out how they got in.

Get help with your site
Gonzalo Puig
Gonzalo Puig Co-Founder, Design and Development

Leads the agency and is part of every project, from the first call to post-launch.

LinkedIn
All articles