Schema.org Metatag


This project is not covered by Drupal’s security advisory policy.

This project extends Drupal's Metatag module to display structured data as JSON LD in the head of web pages. Either hard-code properties or identify patterns using token replacements. Using the override system in Metatag module you can define default structured data values for all content types, override the global content defaults for a particular content type, or even override everything else on an individual node to provide specific values for that node.

This module defines metatag groups that map to Schema.org types, and metatag tags for Schema.org properties, then steps in before the values are rendered as metatags, pulls the Schema.org values out of the header created by Metatag, and instead renders them as JSON LD when the page is displayed.

Since the Schema.org list is huge, and growing, this module only provides a small subset of those values. But it is designed to be extensible. There is an included module, Schema.org Article Example, that shows how other modules can add more properties to types that are already defined. Several types are included which can be copied to add new types (groups) with any number of their own properties.

The module creates the following Schema.org object types:

Read more about JSON LD and Schema.org in an article on Lullabot.com, Create SEO Juice From JSON LD Structured Data in Drupal.

To populate the image width and height properties, use the appropriate tokens. In Drupal 8, the core Token module provides image height and width token. For example, the token [node:field_image:0:width] will be replaced with the width of the first image in field_image on the current node. In Drupal 7, you'll need to enable the Imagecache Token module, which provides the tokens for image dimensions which are missing in Drupal 7.

Validation

For more information and to validate the results:
- https://developers.google.com/search/docs/guides/intro-structured-data
- https://schema.org/docs/full.html
- https://search.google.com/structured-data/testing-tool

Development Roadmap

Once I get the bugs out of the new D7 branch, my hope is to keep the D8 and D7 versions in sync, same content types, properties, etc. So when we add to one branch, add to the other as well. They're able to share Traits and the SchemaMetatagManager code with basically no changes between the versions, and that's where most of the code actually lies. The base classes like SchemaImageBase are similar in the two versions, but there are a number of differences. The development process for adding groups and properties is totally different:

- In D7, create a file MODULE_NAME.metatag.inc and define the groups and properties there. The info array allows you to indicate a class for each property, where you can use the appropriate base class.
- In D8, create groups at MODULE_NAME/src/Plugins/metatag/Group and properties at MODULE_NAME/src/Plugins/metatag/Tag. Each tag extends the appropriate base class.

In either case, in either branch, you should be able to copy one of the existing modules as a starting point.

Example JSON LD

Using this module, the code in the head of the page might end up looking like this:

<script type="application/ld+json">{
    "@context": "https://schema.org",
    "@graph": [
        {
            "@type": "Article",
            "description": "Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Donec sollicitudin molestie malesuada. Donec sollicitudin molestie malesuada. Donec rutrum congue leo eget malesuada. Nulla quis lorem ut libero malesuada feugiat. Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui.",
            "datePublished": "2009-11-30T13:04:01-0600",
            "dateModified": "2017-05-17T19:02:01-0500",
            "headline": "Curabitur arcu erat]",
            "author": {
                "@type": "Person",
                "name": "Minney Mouse",
                "sameAs": "https://example.com/user/2"
            },
            "publisher": {
                "@type": "Organization",
                "name": "Example.com",
                "sameAs": "https://example.com/",
                "logo": {
                    "@type": "ImageObject",
                    "url": "https://example.com/sites/default/files/logo.png",
                    "width": "600",
                    "height": "60"
                }
            },
            "mainEntityOfPage": {
                "@type": "WebPage",
                "@id": "https://example.com/story/example-story"
            },
        },
    ]
}</script>

A new option is an option to "Pivot" multiple values for the Person, Organization, Address, or Offer. If selected, this will change the result from:

<script type="application/ld+json">{
    "@context": "https://schema.org",
    "@graph": [
        {
            "@type": "Event",
            "name": "Premier",
            "url": "example.com/event/premier",
            "description": "Lorem ipsum dolor sit amet, consectetur.",
            "offers": [
                {
                    "@type": "Offer",
                    "price": [
                      "10",
                      "20",
                    ],
                    "priceCurrency": "USD",
                    "url": "https://amazon.com"
                },
            ],
            "actor": {
                "@type": "Person",
                "name": [
                    "Micky Mouse",
                    "Donald Duck",
                    "Tweety Bird"
                ],
                "url": [
                    "https://example.com/person/mickey-mouse",
                    "https://example.com/person/donald-duck",
                    "https://example.com/person/tweety-bird"
                ],
            }
        },
    ]
}</script>

to:

<script type="application/ld+json">{
    "@context": "https://schema.org",
    "@graph": [
        {
            "@type": "Event",
            "name": "Premier",
            "url": "example.com/event/premier",
            "description": "Lorem ipsum dolor sit amet, consectetur.",
            "offers": [
                {
                    "@type": "Offer",
                    "price": "10",
                    "priceCurrency": "USD",
                    "url": "https://amazon.com"
                },
                {
                    "@type": "Offer",
                    "price": "20",
                    "priceCurrency": "USD",
                    "url": "https://amazon.com"
                }
            ],
            "actor": {
                {
                    "@type": "Person",
                    "name": "Mickey Mouse",
                    "url": "https://example.com/person/mickey-mouse",
                },
                {
                    "@type": "Person",
                    "name": "Daffy Duck",
                    "url": "https://example.com/person/daffy-duck",
                },
                {
                    "@type": "Person",
                    "name": "Tweety Bird",
                    "url": "https://example.com/person/tweety-bird",
                },
            }
        },
    ]
}</script>
Supporting organizations: 

Schema.org Metatag项目的Drush安装命令:复制到剪贴板

注:个别模块仍需开启相关子模块。
周安装量: 
59
维护状态: 
正在寻找项目共同维护者
开发状态: 
积极开发中

推荐版本下载:

版本下载地址发布日期发布说明翻译下载
8.x-1.0-rc4tar.gz (24.57 KB) | zip (82.07 KB)2017年8月6日发布说明简 | 繁 | 更多

其他版本下载:

版本下载地址发布日期发布说明翻译下载
7.x-1.0-rc1tar.gz (20.22 KB) | zip (40.87 KB)2017年8月4日发布说明简 | 繁 | 更多

开发版本下载:

版本下载地址发布日期发布说明翻译下载
8.x-1.x-devtar.gz (24.58 KB) | zip (82.12 KB)2017年8月6日发布说明简 | 繁 | 更多
7.x-1.x-devtar.gz (20.23 KB) | zip (40.91 KB)2017年9月13日发布说明简 | 繁 | 更多