How can I include Google Structured Data via a module?

by almcnicoll   Last Updated January 19, 2018 16:07 PM

Looking through Google's suggestions of search optimisation for a site that I control, I would like to add their "Structured Data" JSON to various pages on the site. Their suggestion is to include the data in custom script tags:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Organization",
  "url": "http://website.com",
  "logo": "http://website.com/logo.png",
  "contactPoint": [{
    "@type": "ContactPoint",
    "telephone": "+44 1234 567890",
    "contactType": "customer service"
  }]
}
</script>

What I can't work out is how to include this data "the Drupal way". I tried adding it as a library (thinking I'd later use DrupalSettings to customise the contents) but that includes it as a standard "type=javascript". How do I add it to the page header with the correct script type?

Google ref: https://developers.google.com/search/docs/data-types/corporate-contact

(answers giving a module that does this already are also welcome!)

Tags : 8 json libraries seo


Related Questions


How to make wkhtmltopdf work on Drupal

Updated April 11, 2015 20:03 PM

How to include phpExcel library in controler?

Updated April 15, 2016 08:03 AM

Drupal 8 - GD library

Updated April 28, 2016 08:03 AM

Installing and loading google client php api

Updated April 28, 2015 22:03 PM

How to make sure my libraries loads last?

Updated July 11, 2017 16:07 PM