Skip to content

Add data-nosnippet to related-posts section to prevent snippet cross-contamination - #290

Open
Bluetegu wants to merge 1 commit into
TryGhost:mainfrom
Bluetegu:fix-related-posts-nosnippet
Open

Bluetegu wants to merge 1 commit into
TryGhost:mainfrom
Bluetegu:fix-related-posts-nosnippet

Conversation

@Bluetegu

Copy link
Copy Markdown

Problem

Google can select text from the "Read more" related-posts section at the
bottom of a post page as the search-result snippet for that page, instead of
the post's own content — even though the related posts are unrelated to the
page's actual topic.

For example, a search for "WordA WordB" returned a result linking to a post
whose title contains "WordA", but with a snippet containing "WordB" — text
that doesn't appear anywhere in that post, but does appear in the title/
excerpt of an unrelated post shown in its "Read more" section.

Solution

Add the data-nosnippet attribute to the <section> already wrapping the related-posts block in post.hbs.
This tells Google to never use this section's text for a search snippet
(applies to both classic web search and AI Overviews/AI Mode, per Google's
docs), while leaving the section, its links, and its visual layout completely
unchanged for real visitors.

data-nosnippet only affects snippet text selection — it does not change
crawling, link-following, or indexing behavior in any way. The related-posts
links remain fully crawlable and followable, the section's content stays
indexed and eligible for ranking.

data-nosnippet is documented by Google as supported on span, div, and
section elements specifically — the existing wrapper is already a
<section>, so no tag change is needed, just the one attribute:

-            <section class="gh-container is-grid gh-outer">
+            <section class="gh-container is-grid gh-outer" data-nosnippet>

Alternatives considered

We considered semantic-only alternatives (e.g. wrapping the section in
<aside> instead of <section>), but tag choice alone has no documented
effect on Google's snippet selection — data-nosnippet is the actual,
documented mechanism for this, and Google only guarantees it on span,
div, and section.

Files

  • post.hbs — 1 line changed (added data-nosnippet attribute, no other
    changes)

Testing

  • pnpm install --frozen-lockfile + pnpm test:ci (gulp zip then
    gscan --fatal --verbose .) — ✓ no fatal compatibility issues with Ghost 6.x.
  • Manual visual check: no visible/layout change for real visitors, since
    data-nosnippet has no CSS or rendering effect.

Browser support

data-nosnippet is inert everywhere except crawlers that recognize it —
currently Google (web search and AI Overviews/AI Mode) and, as of October
2025, Bing.
It's a plain HTML data-* attribute with zero visual or functional effect in
any browser or any crawler that doesn't recognize it.


Co-developed with GitHub Copilot.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0bef8f2d-c7ea-41c4-a0a9-b99ab8f616db
Commits

Reviewing files that changed from the base of the PR and between 87b046c and 6b5d7f1.

Files selected for processing: 1
  • post.hbs

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

The related-articles section element in post.hbs now includes the data-nosnippet attribute.

Priority: Low

Estimated code review effort: 1 (Trivial) | ~2 minutes

Change: Bug fix

Suggested reviewers: minimaluminium

Merge Risk: Minimal · up to 6b5d7

No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: adding data-nosnippet to the related-posts section to prevent snippet contamination.
Description check Passed The description directly explains the snippet-selection problem, the data-nosnippet solution, affected file, testing, and expected behavior.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant