Your WordPress Site Got Hacked: What to Do in the First 24 Hours

A hacked site rarely announces itself. More often a client tells you Google shows a warning, your pages redirect to spam, or strange links appear in the footer that you never added. We clean infected WordPress sites regularly, including cases where attackers injected hidden widgets that loaded scripts from outside domains and left backdoor files to get back in after a password change. This guide is the order we follow in the first 24 hours: contain the damage, find how they got in, clean, close the door, and only then restore and tell Google.
Quick answer: Put the site in maintenance mode and take a full backup of the infected state before you touch anything. Then check for unknown admin users, modified core and plugin files, and PHP files hiding in the uploads folder. Replace WordPress core, plugins and themes with fresh copies from official sources, remove every backdoor, and clean the database. Only after that, rotate all passwords, add a firewall and 2FA, and request a review from Google in Search Console.
Signs your WordPress site has been hacked
The most common signs we see:
- A red browser warning or a “This site may be hacked” label next to your site in Google results.
- Redirects to spam, gambling or fake shop pages. Some infections only redirect certain visitors, such as mobile users, so you may not see it yourself.
- Links or text in the footer or sidebar that nobody on your team added.
- Admin users you don’t recognize.
- Spam pages in Google when you search
site:yourdomain.com, often in another language. - Your host suspending the account or warning you about malware.
If you see any of these, follow the timeline below. Speed matters, but order matters more.
The first 24 hours at a glance
| Time | Goal | Key actions |
|---|---|---|
| Hour 0–1 | Contain | Maintenance mode, full backup of the infected state, no blind deleting |
| Hour 1–4 | Investigate | Admin users, checksums, PHP in uploads, widgets, .htaccess, cron jobs |
| Hour 4–12 | Clean | Fresh core, official plugins and themes, remove shells, clean the database |
| Hour 12–24 | Harden and recover | Rotate all passwords, salts, updates, firewall, 2FA, backups, Google review |
Hour 0–1: Contain the damage
Stop visitors from reaching the infected pages
Put the site into maintenance mode to protect visitors and your reputation. On a compromised site a maintenance plugin may itself be unreliable, so a server-level block (through your hosting panel or an .htaccess rule) is often safer. Pause any ads so you are not paying to send people to a hacked page.
Back up the infected state before you change anything
It feels backwards, but it is essential. Copy all files and the database as they are now, label the copy as infected, store it off the server, and never restore from it. This is your evidence of how the attacker got in and what changed.
Don’t delete blindly
Deleting one obvious file usually leaves the backdoors in place and can break the site in ways that hide the real problem. Note what you find, then clean in order.
Secure the hosting account
If someone may still have active access, change the hosting panel password now. Full rotation comes after cleaning; new passwords mean little while a backdoor is still on the server.
Hour 1–4: Find out how they got in
The examples below use WP-CLI, the WordPress command-line tool included with most hosting plans that offer SSH. Without SSH, your host or developer can run them for you.
Check for unknown administrators
Attackers often create an admin account so they can log in normally later:
wp user list --role=administrator
Note any usernames or emails you don’t recognize, especially accounts created around the time the problems started.
Verify core and plugin files
WP-CLI can compare your files against the official copies on wordpress.org:
wp core verify-checksumsreports modified core files and files that should not exist.wp plugin verify-checksums --alldoes the same for plugins from the wordpress.org directory.
Premium plugins and themes can’t be checked this way, so plan to reinstall them from the vendor.
Look for PHP files where they don’t belong
The uploads folder should hold images and documents, not code. Any PHP file there is a red flag:
find wp-content/uploads -name "*.php"
Also list PHP files modified recently, for example find . -name "*.php" -mtime -7 for the last seven days. Attackers can fake file dates, so this is a starting point, not proof.
In cases we have cleaned, web shells sat in both uploads and plugin folders. That is why the owners changed their passwords and still got reinfected: the attacker never needed a password.
Inspect widgets, options and .htaccess
Not all malware lives in files. On one site we handled, attackers had added Custom HTML widgets to the footer and sidebar that loaded base64-obfuscated scripts from an outside domain dressed up as a CDN, and the page builder plugin’s files had been deleted. Check:
- Appearance → Widgets, or
wp option get widget_custom_html, for code you didn’t add. wp option get siteurlandwp option get hometo make sure they point to your domain.- The
.htaccessfile in the root and in subfolders for redirect rules you don’t recognize. - The top of
wp-config.phpand thewp-content/mu-pluginsfolder, which loads automatically and is easy to overlook.
Check scheduled tasks
Some infections reinstall themselves on a schedule. Run wp cron event list and look for hooks that don’t belong to your plugins, then check the cron jobs in your hosting panel.
Identify the likely entry point
Common causes are an outdated plugin or theme with a known vulnerability, nulled (cracked) software, a weak or reused password, leaked FTP credentials, or another infected site on the same hosting account. Compare your host’s access logs with file modification dates. If the entry point stays open, the cleanup won’t last.
Hour 4–12: Clean the site
Replace WordPress core
Don’t repair core files one by one. Replace them with a fresh copy of the same version, leaving wp-content alone:
wp core download --force --skip-content --version=6.x.x
Use your actual version number, then run wp core verify-checksums again and remove any extra files it reports as “should not exist”.
Reinstall plugins and themes from official sources only
Reinstall every free plugin from wordpress.org (for example wp plugin install plugin-slug --force) and every premium plugin or theme from the vendor’s website. Delete plugins and themes you don’t use, since inactive code can still be exploited. Never install nulled or cracked versions; they are a common way malware gets in to begin with.
Remove shells and backdoors
Remove what the investigation found: PHP files in uploads, unknown files in plugin and theme folders, injected code in wp-config.php, and anything unfamiliar in mu-plugins. Then delete the unknown admin accounts.
Clean the database
Remove injected widgets and options, then search the content for scripts or the attacker’s domain, for example wp db search "outside-domain.com". Clear out junk too: on one site we fixed, leftover session rows from a plugin filled the database until the site stopped loading; on another, hundreds of spam comments sat in moderation.
Hour 12–24: Harden and recover
Rotate every password
Now that the backdoors are gone, change every credential: hosting or cPanel, the database user (and update wp-config.php), every WordPress administrator, FTP and SFTP accounts, and the domain’s email accounts. Use a unique password for each.
Reset the security keys
Generate new salts with wp config shuffle-salts. This logs out every user, including any attacker holding a stolen session cookie.
Update everything
Run wp core update, wp plugin update --all and wp theme update --all, and check that PHP on your server is a supported version.
Add a firewall and 2FA
Install a security plugin with a firewall, such as Wordfence, enable two-factor authentication for every admin, and add define( 'DISALLOW_FILE_EDIT', true ); to wp-config.php so nobody can edit code from the dashboard.
Set up offsite backups
Schedule automatic backups stored outside the server and keep several versions. A backup on the same hosting account can be infected or deleted with the site.
Ask Google to review the site
Only after the site is clean, open Google Search Console, go to Security issues, and click Request Review with a short note on what you cleaned. If your rankings or traffic were hit, our SEO team can help with recovery.
Check blacklists and your email
Check your domain in Google’s Safe Browsing site status tool and other public reputation checkers. Check your email setup too: on one domain we reviewed, missing SPF and DKIM records were sending the company’s own mail to spam. Not caused by the hack, but worth fixing at the same time.
When to call a professional
You can follow this guide yourself if you are comfortable with SSH and WP-CLI. Get help if:
- The site keeps getting reinfected after you clean it.
- You don’t have SSH access or a backup from before the infection.
- The site handles bookings, payments or customer data.
- Your host has suspended the account.
- The site is so damaged or outdated that rebuilding is safer than patching.
Perfect Solution 4U has built and managed websites since 2016, most of them for tourism companies. Our hosting, maintenance and security plans cover malware cleanup, monitoring and offsite backups, and our web development team can rebuild a site on a clean base when that makes more sense. Hacked right now? Contact us and tell us what you see.
Frequently asked questions
Can I just restore an old backup?
Only if you are sure it predates the infection, and even then you must find and close the entry point or the attacker will use it again. Infections often sit quietly for a while, so a recent backup may already contain the backdoor.
Is changing my passwords enough?
No. If a backdoor file is on the server, the attacker doesn’t need a password to get back in. Change passwords after you have removed the backdoors, not instead of removing them.
Will a security plugin clean the site for me?
A scanner like Wordfence helps find infected files, but it can miss malware in the database or widgets, and it can’t tell you how the attacker got in. Use it as one tool, not the whole process.
How long does Google take to remove the warning?
It depends on the issue, and Google doesn’t promise a fixed time. Submit the review request in Search Console once the site is clean; the result appears there. Requesting a review too early usually means a rejection and a longer wait.
How do I stop it from happening again?
Keep WordPress, plugins and themes updated, use only official sources, remove what you don’t use, enable 2FA, run a firewall, and keep offsite backups. Regular maintenance is far cheaper than an emergency cleanup.



