The Microdata example of Google’s Article Rich Snippet contains this meta
element with Schema.org’s mainEntityOfPage
property:
<meta itemscope itemprop="mainEntityOfPage" itemType="https://schema.org/WebPage" itemid="https://google.com/article"/>
When checking it with the Nu Html Checker, I get this error:
Element
meta
is missing required attributecontent
.
Adding an empty content
attribute seems to solve this error. Is it correct to do this?
The Nu Html Checker is correct, Google’s example is invalid. The
content
attribute is required if themeta
element has anitemprop
attribute.From WHATWG HTML and also HTML 5.1 (W3C Working Draft): "If […]
itemprop
is specified, then thecontent
attribute must also be specified."From the old Microdata (W3C Note): "If a
meta
element has anitemprop
attribute, […] thecontent
attribute must be present."Adding an empty
content
attribute makes it valid, but there are also other options.Schema.org’s
mainEntityOfPage
property expects as value either a URL or aCreativeWork
item.Google’s own documentation for the recommended/required properties for their Article Rich Snippet says that they expect a URL value, but their examples show how to create an item value.
All of the following solutions are fine according to the Google Structured Data Testing Tool. (Some examples use the
itemid
attribute, which is, strictly speaking, not yet allowed/defined for the Schema.org vocabulary.)If you want to provide a URL value:
Straightforward.
This follows Google’s own recommendation, requires minimal markup, and works in the
head
as well as thebody
.If you have a visible link, you can of course also use an
a
element.If you want to provide an item value:
As type you can use
CreativeWork
or any of its subtypes, likeWebPage
.div
element +url
propertyThis creates a
WebPage
item with aurl
property. It can only be used in thebody
.If you have a visible link, you can of course also use an
a
element.meta
element with emptycontent
attribute anditemid
This is based on Google’s example, but with an empty
content
attribute to make it valid.Note that Microdata parsers have to ignore the
content
attribute in that case, because theitemscope
attribute is provided (Microdata W3C Note/WHATWG HTML Microdata: "first matching case"). So theitemprop
value will be an item, not a string.This creates an empty item with an identifier. Works in the
head
as well as thebody
. It doesn’t allow to add properties directly to thisWebPage
item (you’d have to create another item with the sameitemid
value).div
element withitemid
This creates an empty item with an identifier. Instead of the
meta
example, it only works in thebody
, but therefore allows to add additional properties directly to thisWebPage
item.If you already have a
WebPage
item:If you already provide a
WebPage
item on your page, e.g.,you can make use of it via Microdata’s
itemref
attribute:combined with one of the methods described above, e.g., with
itemid
or aurl
property.Note that you’d typically use the inverse property
mainEntity
in such a case, but Google doesn’t document that they’d support it for the Article Rich Snippet, currently.