How to add a schema for each blog post?


#1

How to add a schema for each blog post, is there is any additional plugin do we need to install?

For example:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "NewsArticle",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://google.com/article"
  },
  "headline": "Article headline",
  "image": [
    "https://example.com/photos/1x1/photo.jpg",
    "https://example.com/photos/4x3/photo.jpg",
    "https://example.com/photos/16x9/photo.jpg"
   ],
  "datePublished": "2015-02-05T08:00:00+08:00",
  "dateModified": "2015-02-05T09:20:00+08:00",
  "author": {
    "@type": "Person",
    "name": "John Doe"
  },
   "publisher": {
    "@type": "Organization",
    "name": "Google",
    "logo": {
      "@type": "ImageObject",
      "url": "https://google.com/logo.jpg"
    }
  },
  "description": "A most wonderful article"
}
</script>


#2

You can save the file inside _include folder and

Option 1

{% include myfile.html %}

in the blog post

or

Option 2

Check what layout your blog is using, for example,

---
layout: mylayout
---

then edit _layout/mylayout.html and add the schema there

Hope this helps.

Cheers


#3

jekyll-seo-tag plugin has limited support for JSON LD ouput


#4

I create JSON-LD templates; there are lots of new and updated schemas that don’t have plugin support.

  • create templates for the schemas you want.

Here’s one for WebSite located at _includes/index.jsonld:

{
  "@context": "http://schema.org",
  "@type": "WebSite",
  "name": "{{ site.title }}",
  "url": "{{ site.url }}",
  "description": "{{ site.description }}",
  "dateModified": "{{ site.time | date_to_xmlschema }}",
  "creator": {
    "@type": "Person",
    "name": "John Doe"
   }
}
  • include it in your layout:
<script type="application/ld+json">
  {% include index.jsonld %}
</script>