WordPress hacked – what now?

Panic makes people delete the suspicious file and hope for the best. That is the fastest way to be hacked again next week. This is the order we work in: shut the site off first, keep the traces, find everything the attacker left behind, and only at the end rotate the keys and reopen.

Last checked:

ChecklistIs the site actually hacked?
  • Visitors who arrive from Google on a phone are sent to another domain, while the site looks normal on your own laptop
  • A site:your-domain.dk search in Google shows pages you never made, often in Japanese or full of pharma and casino text
  • Your host blocks outgoing mail because the account is sending spam
  • There is an administrator nobody recognises, or a PHP file in the uploads folder
  • The browser or Google Search Console warns about harmful content

Is the site actually hacked?

The usual signs are not a skull on the front page. They are quiet:

  • Visitors who arrive from Google on a phone are sent to another domain, while the site looks normal on your own laptop.
  • A site:your-domain.dk search in Google shows pages you never made, often in Japanese or full of pharma and casino text.
  • Your host blocks outgoing mail because the account is sending spam.
  • There is an administrator nobody recognises, or a PHP file in the uploads folder.
  • The browser or Google Search Console warns about harmful content.

Google itself says its warnings depend on how and from where the site is visited, so you cannot always reproduce them; the Security issues report in Search Console is what counts. If you see even one of these signs, treat it as a break-in until you have shown otherwise.

Step 1: Contain – without deleting anything

Maintenance mode is not enough. It shows a notice to normal visitors, but a backdoor in wp-content/uploads/ can still be called directly. So lock the site at the web server level, letting in only your own IP address while you work.

# 1) Notice for visitors (WP-CLI)
wp maintenance-mode activate

# 2) Lock everything else at the web server. Apache 2.4: put this at the top
#    of .htaccess in the site root and replace 203.0.113.10 with your own IP
#
#    Require ip 203.0.113.10
#
# nginx: inside the server block
#    allow 203.0.113.10;
#    deny all;

# 3) Pause WordPress' own scheduled tasks while you investigate
wp config set DISABLE_WP_CRON true --raw

At the same time, change the password for the hosting account and for SFTP/SSH, and remove any SSH keys you do not recognise. Those are the ways in that sit outside WordPress. Passwords, salts and API keys inside WordPress wait until step 6: a backdoor still on the server can read wp-config.php, and the new key with it, straight away.

Step 2: Keep the evidence before you clean up

The infected site shows how the attacker got in and when. Without that you cannot tell which backup is clean, or whether personal data is involved. Take a full copy before you change a single file.

CASE="$HOME/incident-$(date +%F-%H%M)"
mkdir -p "$CASE"

# Every file, with timestamps and permissions kept (-p)
tar -czpf "$CASE/files.tar.gz" -C /var/www example.dk

# The database as it is right now
wp db export "$CASE/database.sql"

# Web server logs – the path differs from host to host
cp -a /var/log/apache2/access.log* /var/log/apache2/error.log* "$CASE/" 2>/dev/null

# Fingerprints, so you can show later that the copy was not altered
( cd "$CASE" && sha256sum * > SHA256SUMS )

Download the folder to another machine. If you cannot reach the logs, ask the host for them the same day, because logs are often kept only briefly. Also start a plain timeline in a document: when you noticed, what you saw and what you did. You will need it in step 8.

Step 3: Which files have changed?

WP-CLI compares your files with the official checksums from wordpress.org. --include-root also checks the site’s root folder and warns about anything that is not part of WordPress.

# Core, including foreign files in the root folder
wp core verify-checksums --include-root

# Every wordpress.org plugin; --strict also reports changed readme files
wp plugin verify-checksums --all --strict --format=csv > "$CASE/plugin-check.csv"

Checksums only cover core and directory plugins. They do not cover themes, paid plugins, mu-plugins, wp-config.php or uploads. Compare those with a fresh copy from the vendor:

# Paid plugin or theme: unpack a clean ZIP next to it and compare
mkdir -p /tmp/clean && unzip -q ~/Downloads/plugin-name-4.2.1.zip -d /tmp/clean
diff -rq /tmp/clean/plugin-name wp-content/plugins/plugin-name

# Everything in mu-plugins runs automatically – know every single file
ls -la wp-content/mu-plugins/

This is where knowing exactly which code runs pays off. On the first client site where we replaced every third-party plugin – a Danish bathroom-renovation company’s website – 13 of the 16 plugins are our own and byte-identical to our code repository. A plugin that matches a known source byte for byte can be checked in seconds. A plugin nobody knows the origin of cannot.

Step 4: Users, sessions and application passwords

Attackers nearly always leave a second way in. A new administrator is the most visible one. An application password on an existing user is harder to spot, because it keeps working even after you change that user’s normal password.

# All administrators – and the ten most recently created users of any role
wp user list --role=administrator --fields=ID,user_login,user_email,user_registered
wp user list --orderby=registered --order=DESC --number=10 --fields=ID,user_login,roles,user_registered

# Multisite: who is a super admin?
wp super-admin list

# Application passwords for every administrator, with last use and IP
for id in $(wp user list --role=administrator --field=ID); do
  echo "== user $id"
  wp user application-password list "$id" --fields=uuid,name,created,last_used,last_ip
done

# Remove an unknown user (content goes to user 1) and all app passwords
wp user delete 57 --reassign=1
wp user application-password delete 1 --all

If the site does not use application passwords for an app or an integration, switch the feature off completely afterwards. It is one of the doors our own product Lynbro Shield closes by default, together with the code editor in wp-admin and PHP in uploads.

Step 5: Find the injected code

Now you hunt for the backdoors. The patterns below also give false positives – plenty of legitimate plugins use base64_decode – so read every hit instead of deleting blindly.

# PHP in uploads is almost always a backdoor
find wp-content/uploads -type f \( -iname '*.php' -o -iname '*.phtml' -o -iname '*.phar' \)

# PHP files changed in the last 21 days, newest first (Linux find)
find . -type f -name '*.php' -mtime -21 -printf '%TY-%Tm-%Td %TH:%TM  %p\n' | sort -r | head -40

# Classic patterns: eval of encoded text, and code that runs input directly
grep -rnE --include='*.php' 'eval\s*\(\s*(base64_decode|gzinflate|gzuncompress|str_rot13)' wp-content/ | cut -c1-180
grep -rnE --include='*.php' '(assert|system|shell_exec|passthru)\s*\(\s*\$_(POST|GET|REQUEST|COOKIE)' . | cut -c1-180

# New or changed .htaccess files can redirect mobile traffic
find . -name '.htaccess' -mtime -21 -ls

Many attacks are not in files at all but in the database: a script in an option that loads on every page, a post with hidden links, or a changed address in siteurl.

P=$(wp db prefix)

# Options containing script tags or encoded JavaScript
wp db query "SELECT option_name, autoload, LENGTH(option_value) AS bytes
  FROM ${P}options
  WHERE option_value REGEXP '<script|eval[(]|base64_decode|fromCharCode|atob[(]'
  ORDER BY bytes DESC LIMIT 25;"

# Does the site still point to your own domain?
wp option get siteurl && wp option get home

# Content with script tags, most recently changed first
wp db query "SELECT ID, post_type, post_status, post_modified FROM ${P}posts
  WHERE post_content LIKE '%<script%' ORDER BY post_modified DESC LIMIT 25;"

# Scheduled tasks: know every hook – an unknown one can rebuild the backdoor every hour
wp cron event list --fields=hook,recurrence,args --format=csv

Do not forget code-snippet plugins. They keep their code in the database, so grep will not find it. When we scanned the sites we look after, seven had such a plugin. Open the snippet list in wp-admin and delete anything you did not write yourselves.

Restore or clean in place?

Restore, clean or start over

RouteWhenUpsideThe catch
Restore from backupYou have a backup from before the first trace on the timelineFastest, and everything is knownThe backup still has the vulnerable plugin; orders and form entries since then are lost
Clean in placeNo clean backup, or it is too oldNo content lostOne missed backdoor and the attacker is back
Fresh install + content importThe attack has run for a long time, or no file can be trustedCleanest resultMost work: theme, plugins and settings are set up again
Our own criteria after a break-in. In all three cases the hole the attacker used must be closed before the site reopens.

A backup is only clean if it is older than the first trace on the timeline from step 2 – not merely older than the day you noticed. If you run a shop, export orders and customers from the period after the backup before you restore, or they disappear.

If you choose to clean, replace code with fresh copies rather than patching file by file:

# Fresh core files in the same version – leaves wp-config.php and wp-content alone
wp core download --version="$(wp core version)" --skip-content --force

# Reinstall each wordpress.org plugin in the version you have
wp plugin list --fields=name,version --format=csv | tail -n +2 |
while IFS=, read -r name version; do
  wp plugin install "$name" --version="$version" --force --quiet \
    || echo "Not on wordpress.org – get it from the vendor: $name"
done

# Run the check again: "File should not exist" = a file the attacker added
wp core verify-checksums --include-root

wp core download --force overwrites core files but does not delete extra files the attacker put in wp-admin or wp-includes. That is why you run the check afterwards. Then update everything to the latest version before the site reopens, or the attacker walks in the same way again.

Step 6: Rotate every key – now, not earlier

Only once the backdoors are gone does it make sense to change the secrets stored in WordPress:

# New salts: every login session and cookie becomes invalid
wp config shuffle-salts

# New database password: change it at the host first, then in wp-config.php.
# read -s keeps the password out of the shell history
read -rs -p "New database password: " NEWPW && wp config set DB_PASSWORD "$NEWPW" && unset NEWPW

# Which options look like stored keys? (payments, SMTP, AI, APIs)
wp option list --search='*key*' --fields=option_name
wp option list --search='*token*' --fields=option_name
wp option list --search='*secret*' --fields=option_name

Work through the list and issue new keys at every service: payments, shipping, SMTP, accounting and AI. Our own plugins with AI features only use your own key , and our CVR lookup plugin keeps its key encrypted on the server. That protects against a leaked database backup – but not against an attacker who could run code on the server. After a break-in you therefore rotate every key, encrypted ones included. Finally, give everyone with access a new password and two-factor login.

Step 7: Reopen – and check that what visitors see is clean

The cache can keep serving infected pages after the files are clean. On one of our own sites the cache plugin had never purged anything, because the server’s open_basedir setting blocked it. Purge the page cache, the object cache and any CDN, then view the site in a private window, on a phone and through a Google search result.

Turn DISABLE_WP_CRON off again (or let the server run cron), remove the IP lock and switch off maintenance mode with wp maintenance-mode deactivate. If Google flagged the site, fix every item in the Security issues report and choose Request review. Google says a review can take from several days to weeks.

Then close the doors for next time. The standing checklist for hardening, logins and plugin hygiene is on the WordPress security page. Two points from our own operations: a Content Security Policy stops injected scripts from foreign domains, but switch it on in report-only mode first and read the reports – that is how we went from reporting to enforcing ourselves. And repeat the scans from steps 3–5 after one day and after one week. Those are the same follow-up checks we run after every plugin switch , and a missed backdoor tends to show itself in that window.

Step 8: Who needs to be told?

Your host needs to know if the account sent spam, and your agency or IT supplier needs to know if they have access. The big question is personal data.

Check what was in the database. Contact forms that store submissions – which we recommend, because mail from the site can fail without any error – mean names, e-mail addresses and messages are in there. A WooCommerce shop holds orders and addresses. If the attacker could have reached them, it is a personal data breach.

Under GDPR Article 33 the controller must notify Datatilsynet (the Danish Data Protection Agency) via Virk.dk without undue delay and, where feasible, within 72 hours of becoming aware of the breach, unless it is unlikely to result in a risk to the people concerned. The deadline also runs at weekends and on public holidays, the information can be given in stages, and a late notification must state the reasons. If your agency or host discovers the breach as a processor, they must tell you without undue delay. The form on Virk.dk asks, among other things, about the nature of the breach, the likely consequences and the measures you have taken – exactly the timeline from step 2.

Whether the people affected must also be told directly depends on the risk. Datatilsynet’s guidance describes when; the assessment is yours. If your company falls under NIS2, the incident notice also goes through virk.dk, where you can mark that Datatilsynet should receive the same notification. Before you e-mail customers about the breach or about new passwords, check that mail from the site actually arrives.

Questions about a hacked WordPress site

Can I not just delete the infected file?

Only if it is the only one. Attackers usually leave several backdoors: a file in uploads, an extra administrator, a scheduled task or a script in the database. Go through steps 3–5 before you call the site clean.

How long does the clean-up take?

It mostly depends on whether you have a clean backup. With one, it is a restore, an update and a new scan. Without one, every file and every table has to be reviewed – and then comes the time Google needs to lift any warning.

Do we have to notify Datatilsynet if the site holds no customer data?

That depends on whether personal data was actually on the site – form submissions and user accounts count too. The assessment and any notification belong to the controller. Write the assessment down, whatever you conclude.

Will a security plugin help now?

A plugin can find known patterns and close doors from now on, but it cannot guarantee that everything has been found. Use it as an extra check on top of steps 3–5, not instead of them.

Why do we get hacked again after cleaning up?

Usually because the hole was not closed: the vulnerable plugin came back with the backup, an application password was missed, or a scheduled task rebuilt the backdoor. Update everything and repeat the scan after one day and after one week.

Sources

Last reviewed: 2026-12-04

Fixed price, no commitment

Get a free WordPress check

Tell us briefly what you use today and what you want to achieve. A person answers by e-mail with a proposal and a fixed price before any work starts.

  • A fixed price before we start
  • An answer by e-mail, no calls
  • Your details are used only to answer you

Fields marked with * are required.

What is it about?