Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schema.org <head> HTML markup: can I just use the meta tags?

So I was looking at Schema.org. Do I need to change my <html> tag to this

<html itemscope itemtype="http://schema.org/Article">

or can I just use only the meta tags within my <head></head> block?

<meta itemprop="name" content="The Name or Title Here">
<meta itemprop="description" content="This is the page description">
<meta itemprop="image" content="http://www.example.com/image.jpg">
like image 999
C0nw0nk Avatar asked Oct 06 '17 16:10

C0nw0nk


2 Answers

Properties need to belong to an item. You create an item with the itemscope attribute (and the itemtype attribute can give this item a type).

Without itemscope, your markup example is invalid.

It is possible to provide Microdata only within the head element, but it’s not recommended for two reasons:

  • Microdata was intended to be used on your existing markup. While it can often make sense to include certain meta/link elements in the head (with itemref, see an example), most of the content is typically in the body. If you only want to use elements within head, you would have to duplicate most your content. But if you want to go that route, you might prefer to use JSON-LD.

  • As head doesn’t allow the use of a grouping element (like div), it gets complex to express Microdata. You would have to use itemref for every property and misuse an element like style for every item (see the first snippet in this answer as example).

Your example could look like this:

<head>
  <style itemscope itemtype="http://schema.org/Article" itemref="p1a p1b p1c"></style>
  <meta id="p1a" itemprop="name" content="The Name or Title Here">
  <meta id="p1b" itemprop="description" content="This is the page description">
  <link id="p1c" itemprop="image" href="http://www.example.com/image.jpg">
</head>

If you can use itemscope on the head element, it would be better:

<head itemscope itemtype="http://schema.org/Article">
  <meta itemprop="name" content="The Name or Title Here">
  <meta itemprop="description" content="This is the page description">
  <link itemprop="image" href="http://www.example.com/image.jpg">
</head>

But as soon as you need more than one item (which is typically the case, e.g., for the Organization/Person which is the author etc.), this doesn’t work anymore, and you would need a solution like in my first snippet.

Note that it’s allowed to use meta/link elements for Microdata within the body element. This makes it way easier, as you can use div elements for the itemscope. So even if you duplicate your content instead of marking up your existing content, it would be preferable to do this in the body:

<div itemscope itemtype="http://schema.org/Article">
  <meta itemprop="name" content="The Name or Title Here">
  <meta itemprop="description" content="This is the page description">
  <link itemprop="image" href="http://www.example.com/image.jpg">
</div>

(I replaced the meta element for the image property with a link element, because using meta is invalid for this purpose.)

like image 180
unor Avatar answered Sep 22 '22 12:09

unor


According to the given example from scheme.org, yes both are compulsory for Google.

To validate whether your data is being captured properly you can use this tool:

Structured data testing tool

By using the tool above you can see that if you omit itemtype="http://schema.org/Article" the data will not get captured.

like image 22
Vincent1989 Avatar answered Sep 21 '22 12:09

Vincent1989