搜索结果中的微数据站点名称:"此时元素链接上不允许使用属性itemprop."

rol*_*and 3 html5 w3c-validation microdata

来自Google Developers的我将此示例用于Microdata,以在搜索结果中包含网站名称:

<head itemscope itemtype="http://schema.org/WebSite">
    <title itemprop='name'>Your WebSite Name</title>
    <link rel="canonical" href="https://example.com/" itemprop="url">
</head>
Run Code Online (Sandbox Code Playgroud)

使用W3C Validator我收到此错误消息:

错误:此时元素链接上不允许属性itemprop.

什么是正确的标记?

uno*_*nor 5

根据WHATWG的HTML,link不能有一个rel 一个itemprop属性.根据W3C的微数据(这是一个不再更新的注释),两个属性可以一起使用.有关详细信息,请参阅我在同一元素上的'itemprop'和'rel'属性问题.

因此,如果要符合这两个规范,则必须复制该link元素:

<head itemscope itemtype="http://schema.org/WebSite">
    <title itemprop="name">Your WebSite Name</title>
    <link itemprop="url" href="https://example.com/">
    <link rel="canonical" href="https://example.com/">
</head>
Run Code Online (Sandbox Code Playgroud)