WordPress Hacked Redirect: How to Detect and Clean It
WordPress hacked redirect sending visitors to spam? Confirm it, back up, find the hidden code, clean the site and get Google to clear the warning.
Murad Raza
Freelance Full-Stack Developer

A WordPress hacked redirect is malicious code that sends some of your visitors to a spam, scam or malware site. To fix it, confirm the redirect, save a copy of the infected site, replace WordPress core files, check plugins, themes, .htaccess, users and the database, then change every password. Deleting the one file you spot first rarely finishes the job, because attackers can leave a second way back in.
I'm Murad Raza, a freelance web developer who has built websites, including WordPress sites, since 2022. This guide is based on official WordPress and Google documentation, not on a test I ran for this article.
Key Takeaways
- A redirect can target only some visitors, so "it works for me" proves nothing.
- Back up the infected site before you clean it.
- Replace core files from a clean copy, and do not use the reinstall button in wp-admin.
- Check for a back door: unknown admins, odd files and changed database settings.
- If Google flagged the site, request a review only after every page is fixed.
Why you may not see the redirect yourself
Hacked redirects are built to hide. Google's spam policies warn that hackers may inject code that "redirects some users to harmful or spammy pages", and that they often use cloaking to make a hack harder for the owner to detect.
In practice, the code may ignore logged-in admins, or fire only for people arriving from a search result or on a phone. That is why a customer can report a problem you cannot reproduce.
Step 1: Confirm the redirect
Run these checks from a device that has never logged in to the site:
- Search for your business on a phone using mobile data, then tap your own result.
- Open a private window and visit a few inner pages, not only the homepage.
- Use the URL Inspection tool in Google Search Console. It offers options to test a live URL, so you can check the page Google receives instead of the one your logged-in browser shows.
- Open the Security Issues report in the same tool. It shows warnings when Google finds that a site might have been hacked.
- Check Google Safe Browsing for your domain.
Write down the affected URLs, where visitors land and when. The official WordPress hacked site FAQ puts documenting the problem near the top of its list.
Step 2: Contain it and save a copy
Tell your hosting provider first. The WordPress FAQ notes that a hack "may have affected more than just your site, especially if you are using shared hosting". Ask whether they can see the infection, and whether they hold a clean backup from before it began.
Next, download a full copy of your files and database, even though they are infected. It is your safety net if a cleanup step breaks something.
If you have a clean backup and know roughly when the hack started, restoring it is often the quickest route. A WooCommerce store would lose any orders placed since that backup, so export recent orders first. A restore also leaves the original weakness in place, so still complete Steps 5 and 6.
Step 3: Replace WordPress core and check plugins
Core files should match the official release exactly, so tampering is easy to catch there. If your host offers WP-CLI (a command line tool for WordPress), run:
wp core verify-checksums
wp plugin verify-checksums --all
The core command compares your files with WordPress.org's checksums, and the plugin command does the same for plugins. Premium plugins bought elsewhere may not be covered, so replace those with a fresh download from the vendor.
To clean core, upload fresh copies of /wp-admin, /wp-includes and the root-level WordPress files (such as index.php and wp-login.php, but never wp-config.php) over SFTP, the secure file access your host provides. Use the same WordPress version your site runs, and leave wp-content for Step 4. The FAQ specifically says not to use the reinstall option inside wp-admin, so do this step outside the dashboard.
Delete any plugin or theme you do not use, and reinstall the rest from a trusted source.
Step 4: Hunt the places redirects hide
Check each of these locations:
| Where to look | What a hack looks like |
|---|---|
.htaccess | Rewrite rules outside the standard WordPress block, often pointing at another domain |
wp-config.php | Long encoded strings or includes you do not recognise |
wp-content/uploads | PHP files other than empty index.php placeholders |
wp-content/mu-plugins | Must-use plugins nobody on your team added; they load without being activated |
Theme header.php, footer.php, functions.php | Unfamiliar scripts or encoded code |
Database wp_options (the site settings table) | siteurl or home changed, or scripts stored in settings |
| Database posts | <script> tags injected into page content |
| Users screen | Administrator accounts you do not recognise |
Treat base64_decode, eval and gzinflate in a PHP file as a reason to look closer. Legitimate plugins can use them too, so compare against a clean copy before you delete anything.
Step 5: Lock every door
Once the code is gone, assume all logins were exposed. Change the passwords for WordPress users, hosting, SFTP and the database, then put the new database password in wp-config.php.
Update the secret keys in wp-config.php too. As the WordPress FAQ explains, this "will force anyone that might still be logged in off". Then update WordPress, plugins and themes, since an outdated component may be how the attacker got in. Also check other sites in the same hosting account and your host's cron jobs, since either can reinfect a clean site.
Finally, retest from a clean device for several days. If the redirect returns, a back door is still there, and it is time to bring in a specialist. You can contact me with the notes from Step 1. My WordPress security checklist covers what to lock down for the long term.
Step 6: Ask Google to clear the warning
If the Security Issues report lists a problem, select Request Review only when you are confident every page is clean. Google's guide to requesting a review says a hacked-with-spam review "can require up to several weeks to process", while malware reviews take a few days. If the site passes, it says browser and search warnings are removed within 72 hours.
To reduce the chance of a repeat, a website maintenance plan can handle updates, backups and monitoring for you.
Frequently asked questions
01Why does the redirect only happen on my phone?
02Will a security plugin remove the hack?
03Will a hacked redirect hurt my Google rankings?
04Should I just restore a backup?
Need this fixed on your site?
I Build Websites That Work as Hard as You Do


