0

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!)

  • In case you weren’t aware: Drupal comes with RDFa support, which is one of three syntaxes supported by the Schema.org sponsors (the other two are JSON-LD and Microdata). – unor Jan 20 '18 at 4:23
1

There is a Drupal 8 module works tandem with the Metatag module: Schema.org Metatag

From the module description:

This project extends Drupal's Metatag module to display structured data as JSON LD in the head of web pages. Read more about Schema.org, JSON LD, and how this module works in an article on Lullabot.com, Create SEO Juice From JSON LD Structured Data in Drupal.

|improve this answer|||||
0

You can define the type attribute this way :

google_search:

        version: 1.x

        js:

          js/lib/library/google-search.js: { attributes: {type: application/ld+json} }
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.