Find and Remove Spam Links Injected Into Posts on WordPress

By Information Security Asia · Updated December 3, 2026 · 6 min read

Find and Remove Spam Links Injected Into Posts on WordPress

Short answer: To find and remove spam links injected into posts, first confirm the links exist by viewing your page source or searching the database for the spam domains and common hiding tricks such as display:none, position:absolute with negative offsets, or font-size:0. Back up the database before touching anything. Then remove the links: edit a few posts by hand, or for many posts use a careful database search with a tested query or a search-and-replace tool, checking post content, revisions, widgets, options and theme files. Finally, close the entry point by changing passwords, updating or removing vulnerable plugins and checking for new admin users, or the links will return within days.

Link injection is a quiet kind of hack. Instead of defacing your site, attackers add links to casinos, loans, adult sites, replica goods or pharmacies inside your existing posts. The links are usually hidden from visitors with CSS or placed in tiny text, so you may only notice when Google Search Console reports spam, rankings drop or a reader mentions strange anchors in an RSS feed.

Find and Remove Spam Links Injected Into Posts on WordPress

The goal is to borrow your site’s reputation to boost the spammer’s pages in search results. Google treats this as site abuse, and a site full of hidden links can lose visibility. Unlike pharma hacks that often cloak content only for Google, injected links are frequently stored directly in the database, which makes them easier to find if you know where to look. For cloaked variants, see our guide to pharma hack cleanup.

Step 1: Confirm and identify the spam

Open a few affected posts and view the page source, then search for http to see every link. Look for anchors pointing to unfamiliar domains, especially inside elements with styles that hide them. Note the domains and any unusual markup you find, because you will search for these patterns later.

Common hiding techniques include:

  • Inline styles such as display:none, visibility:hidden or font-size:0.
  • Absolute positioning far off-screen, for example left:-9999px.
  • Links wrapped in elements with the same color as the background.
  • Links placed inside noscript tags or HTML comments.
  • Many links appended at the end of each post in a single block.

Also check the RSS feed and the same post viewed while logged out, since some injections are hidden from logged-in administrators.

Step 2: Back up before cleaning

Take a full database backup and a copy of your files before editing anything. WordPress.org’s hacked-site guidance stresses backing up the infected environment first, both as evidence and as a fallback if cleanup goes wrong. Bulk database edits are powerful and easy to get wrong.

Step 3: Search the database

Injected links usually live in the post_content column of the wp_posts table. Use phpMyAdmin or Adminer from your hosting panel, or WP-CLI if you have it, to search for the spam domains. A read-only query lets you see the scale before changing anything:

SELECT ID, post_title, post_type, post_status FROM wp_posts WHERE post_content LIKE '%spam-domain.example%';

Replace spam-domain.example with the domains you found, and adjust the table prefix if yours is not wp_. Run similar searches for display:none and for the off-screen positioning pattern. Remember that revisions are stored as posts too, with post_type set to revision.

Location Table or place What to check
Post and page content wp_posts, post_content Spam domains, hidden styles
Revisions wp_posts, post_type revision Copies of injected content
Widgets and theme options wp_options Text widgets, footer settings
Custom fields wp_postmeta Page builder data
Theme and plugin files functions.php, footer.php Code that adds links on output

For a handful of posts, edit them in the WordPress editor using the code view and delete the injected markup. For dozens or hundreds, a careful database approach is faster. If every injection is identical, a search-and-replace tool or WP-CLI’s search-replace command with the dry-run option lets you preview changes before applying them. If the injected blocks vary, you may need a pattern-based cleanup, which is best done on a staging copy first.

Find and Remove Spam Links Injected Into Posts on WordPress

Do not forget page builder data stored in post meta, which can contain its own copy of content. Clean revisions too, or delete old revisions once the live content is clean, so the spam cannot be restored accidentally.

If links appear on pages but are not in the database, the injection is happening at output time through code in a theme or plugin file. Compare theme and plugin files with fresh copies, and look closely at functions.php and footer templates.

Step 5: Close the entry point

Link injection usually comes from stolen admin credentials, a vulnerable plugin or a backdoor. Work through the standard steps: change passwords for WordPress admins, hosting, SFTP and the database, enable two-factor authentication, replace secret keys in wp-config.php to log everyone out, update everything and remove unused plugins. Check for new administrator accounts. Our guide to WordPress database security covers least-privilege database users and hunting injected rows, which helps prevent repeat attacks.

Once the site is clean, check Search Console for manual actions or security issues and request a review if one applies. Use URL Inspection on a few cleaned pages to confirm Google sees the fixed version. If spam pages were also created, remove them so they return 404 or 410, and submit an updated sitemap. Our walkthrough of the Japanese keyword hack shows how to purge spam URLs from Google.

Set up early warning so the next injection is caught fast

Link injection often goes unnoticed for months because nothing visibly breaks. A few lightweight checks shorten that window. First, keep Google Search Console verified and email alerts turned on, so security issues and manual actions reach you directly. Second, save a simple database query or a security plugin report that lists posts modified recently, and review it weekly; spam injections usually touch many posts at once, which stands out against your normal editing pattern. Third, turn on an activity log that records who edited which post and when. If an administrator account you rarely use suddenly edits two hundred posts at 3 a.m., you will know where the attack came from.

Finally, check your outbound links from time to time. Several SEO tools and crawlers can list every external domain your site links to. Scanning that list for casinos, loans or pharmacies takes a few minutes and catches injections that hide well in the page source.

Frequently asked questions

Why can I not see the spam links on my site?

Injected links are often hidden with CSS or shown only to logged-out visitors and search engines. View the page source while logged out and search the database.

Is it safe to run a search-and-replace on the database?

Yes, if you back up first and preview changes. Use tools that handle serialized data correctly, and test on a staging copy when possible.

Should I delete all post revisions?

Deleting old revisions after cleanup removes stored copies of the spam. Keep a backup in case you need an old version for other reasons.

Will Google penalize my site for injected links?

Hidden links can lead to lost rankings or a manual action. Cleaning the site and requesting review where needed usually restores normal visibility over time.

Sources

Keep reading