Forum Discussion

Claudius's avatar
10 months ago

How to add Article Page Structured Data markup

Article Structured Data markup in your blog "can help Google understand more about the web page and show better title text, images, and date information for the article in search results on Google Search and other properties (for example, Google News and the Google Assistant)". 

Here's some working code to add a simple JSON linked data set to be used on the BlogArticlePage. Ideally you would drop this in a custom component which you add to that page layout. Since it's not rendering I would recommend adding it somewhere in the footer.

 

<#-- This component will add structured markup in form of JSON linked data for BlogArticlePage. See doc at https://developers.google.com/search/docs/appearance/structured-data/article -->

<#attempt>
	<#assign images = (liql('SELECT original_href,width FROM images WHERE messages.id = "${page.context.message.uniqueId}"').data.items) />
<#recover>
</#attempt>
  
<script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "NewsArticle",
      "headline": "${page.context.message.subject}",
  <#if images?? && (images?size gt 0) >
	<#attempt>
      "image": "${http.request.serverName}${images[0].original_href}",
	<#recover>
      "image": "${http.request.serverName}${asset.get("/html/assets/community-default-image.png")}",
	</#attempt>
  </#if>
      "datePublished": "${page.context.message.postDate?datetime}",
      "author": [{
          "@type": "Person",
          "name": "${page.context.thread.topicMessage.author.login}",
          "url": "${page.context.thread.topicMessage.author.webUi.url}"
        }]
    }
</script>

 

This is a MVP version as it's lacking some details that are part of (but not required) Google's spec:

  • dateModified - Should include the timestamp the blog article was last edited. This is not available via a context object but would require querying the message collection for last_edit_time
  • List of all authors - Currently I'm listing only the initial article author, but no contributors. The author property would be enhanced to something like

 

"author": [{
          "@type": "Person",
          "name": "LauraV",
          "url": "https://community.khoros.com/t5/user/viewprofilepage/user-id/107047"
        },{
          "@type": "Person",
          "name": "John D",
          "url": "https://community.khoros.com/t5/user/viewprofilepage/user-id/27326"
      }]

 

Please give it a spin, validate everything is working correctly in Google Search Console, Schema Markup Validator, or Google's Rich Results Test Tool and be a happier Community Manager / Operations person.

Should you happen to improve the above script and add any missing feature please share them back here.

No RepliesBe the first to reply