Remove wrong structured data from every subpage – add "Sitelinks Search Box" to the homepage only

TL;DR: Right now we are telling Google for every page, subpage, topic, whatsoever that the page itself has "url":"https://www.example.com/"
– this is definitely wrong for a topic page with url like https://meta.discourse.org/t/add-sitelinks-search-box-to-the-homepage-only/219299


The Sitelinks Search Box’ code is implemented on every page, category and topic right now:

<script type="application/ld+json">
{
  "@context":"http://schema.org",
  "@type":"WebSite",
  "url":"https://www.example.com/",
  "potentialAction":{
    "@type":"SearchAction",
    "target":"https://www.example.com/search?q={search_term_string}",
    "query-input":"required name=search_term_string"
  }
}
</script>

E.g. see Google Search Console report ‘Enhancements’ → ‘Sitelinks searchbox

As of Google it should be added to the homepage only:


2 Likes

Some more background on Googles: “Add [the search snippet application/ld+json data] markup only to the homepage, not to any other pages.”

This <script type='application/ld+json'> gives Google information on the content of the actual page/url it is defined on.

Right now we are telling Google for every page, subpage, topic, whatsoever that the page itself is:

  • "@type":"WebSite"
  • "url":"https://www.example.com/"
    – this is definitely wrong for a topic page with url https://meta.discourse.org/t/add-sitelinks-search-box-to-the-homepage-only/219299

Either we should remove the application/ld+json data from every page except of the homepage.
Or we should declare for every subpage the correct page-individual application/ld+json data representing the content of that page.

Examples on how to correctly use application/ld+json data for List-pages e.g. “Carousel”

3 Likes

Yeah, this feature only belongs on home pages and category/tag pages, pr welcome to improve

2 Likes

This PR DEV: output sitelinks search tag on homepage only by rr-it · Pull Request #16157 · discourse/discourse · GitHub removes the structured data from every page - except of the homepage. Homepage is the selected homepage: e.g. homepage, categorie-overview, topic-list…

My assumption is that there is no need for this structured data on category and tag pages.

1 Like

Hey there, thanks for your great PR – it is now merged.

2 Likes