Initial assessment without passwords Quote before intervention One accountable specialist from start to finish

Malware & Security

WordPress Redirecting to Spam Sites: How to Find the Injection

Malicious redirects often fire only on mobile or from search. Here is where the payload hides and the exact commands to find it before you clean.

Short answer: your site is serving injected code that sends some visitors elsewhere. The redirect is usually conditional — mobile only, search referrers only, or once per visitor — which is why you often cannot reproduce it from your own desktop.

Reproduce and record the trigger first

Before touching anything, note which device, browser, country and referrer reproduce it, and where it sends you. Test as a Google visitor and on mobile. These conditions locate the payload and are the only way to prove afterwards it is gone. Do not repeatedly open the destination from a machine holding important logged-in sessions.

Search every layer — the exact places to look

  • Database: check wp_options for tampered siteurl and home, then search all tables for injected <script> or the attacker’s domain.
  • Files: over SSH, grep -RIlE 'eval\s*\(|base64_decode\s*\(|gzinflate\s*\(|str_rot13\s*\(|assert\s*\(|create_function\s*\(' wp-content/ surfaces obfuscated code. Check header.php, footer.php, functions.php and any .php inside /wp-content/uploads.
  • Server rules: .htaccess often carries conditional redirects keyed on user-agent or referrer.
  • Auto-loaded code: a dropped file in /wp-content/mu-plugins loads on every request and hides from the plugin list.
  • Scheduled tasks: inspect the cron array (wp cron event list) for a task that re-injects the code.

Why deleting one line is not a cleanup

The visible redirect is usually the last stage. If a backdoor remains, or the credential the attacker used is still valid, it returns within hours. A real cleanup compares files against clean copies (reinstall core and plugins from source), removes persistence, closes the entry point, and rotates every credential — WordPress, database, SFTP and hosting.

Verify under the original trigger

Re-test using the exact device, referrer and network that reproduced it, with every cache and the CDN purged — a redirect can survive in a cached response after the source is clean. Then monitor for several days, because reinfection from a missed backdoor usually returns quietly.

WP REPAIR INCIDENT STANDARD

Reconstruct the incident before fixing it

Conditional spam redirects are an incident, not a single bad line. Reproducing the trigger, preserving evidence and finding persistence are required before cleanup can be verified.

WP RepairDiagnostic model
1Trigger2Payload3Persistence4Entry point
Follow the chain until you find the first point that stops behaving as expected.
  1. 1

    Record device, referrer, geography, cookies and destination URL that reproduce the redirect.

  2. 2

    Search files, database, server rules, mu-plugins and scheduled tasks.

  3. 3

    Compare installed core, plugin and theme files with clean upstream packages.

  4. 4

    Identify the vulnerable component or credential that allowed the change.

What must be verified

  • The original conditional trigger no longer redirects.
  • Clean file comparisons and user/cron/database reviews show no persistence.
  • Credentials are rotated and the entry point is patched or removed.

BEFORE YOU SEND THE REQUEST

Frequently asked questions.

Do you ask for passwords in the form?+

No. The public form never requests access. Secure credentials are requested only after the scope and quote are approved.

Who reviews the incident?+

The request goes to Jordi Ensenyat, founder of Code Barcelona and a WordPress specialist with more than 15 years of experience.

Is anything changed before the quote?+

No. Visible symptoms and scope are reviewed first. Intervention begins after approval and with a rollback path prepared.

Do you work internationally?+

Yes. WP Repair handles WordPress and WooCommerce incidents in English and Spanish through a remote service.

Assess my incident