【问题标题】:Do you put Schema Microdata meta tags in the html body?您是否将 Schema Microdata 元标记放在 html 正文中?
【发布时间】:2014-04-25 22:36:27
【问题描述】:

我在互联网和stackoverflow上搜索了很长时间来寻找这个问题的答案,我发现链接说你不应该在正文中放置元标记:

虽然 schema.org 网站清楚地显示元标记直接嵌套在正文中 http://schema.org/AggregateRating

看看张贴在那里的例子

 Customer reviews:

  <div itemprop="reviews" itemscope itemtype="http://schema.org/Review">
    <span itemprop="name">Not a happy camper</span> -
    by <span itemprop="author">Ellie</span>,
    <meta itemprop="datePublished" content="2011-04-01">April 1, 2011
    <div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
      <meta itemprop="worstRating" content = "1">
      <span itemprop="ratingValue">1</span>/
      <span itemprop="bestRating">5</span>stars
    </div>
    <span itemprop="description">The lamp burned out and now I have to replace
    it. </span>
  </div>


 <div itemprop="reviews" itemscope itemtype="http://schema.org/Review">
    <span itemprop="name">Value purchase</span> -
    by <span itemprop="author">Lucas</span>,
    <meta itemprop="datePublished" content="2011-03-25">March 25, 2011
    <div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
      <meta itemprop="worstRating" content = "1"/>
      <span itemprop="ratingValue">4</span>/
      <span itemprop="bestRating">5</span>stars
    </div>
    <span itemprop="description">Great microwave for the price. It is small and
    fits in my apartment.</span>
  </div>

如果您要在&lt;head&gt; 中保留元标记,那么您如何将这两个日期与他们的评论联系起来? &lt;meta itemprop="datePublished" content="2011-04-01"&gt; &lt;meta itemprop="datePublished" content="2011-03-25"&gt;

这引起了混乱,我想知道如何正确地做到这一点。

【问题讨论】:

    标签: html microdata schema.org


    【解决方案1】:

    如果是meta 元素

    • 具有itemprop 属性和content 属性,并且
    • 没有name 属性,没有http-equiv 属性,也没有charset 属性,

    那么在body 中有这个meta 是有效的。 (如果值是 URL,你must use link instead。)

    为什么?因为the Microdata specification changes HTML5

    (注意在某些情况下RDFa also changes HTML5 by allowing meta in the body。)


    如果您要在&lt;head&gt; 中保留meta 标签,那么您如何将这两个日期与他们的评论联系起来?

    你可以use the itemref attribute:

    <!DOCTYPE html>
    <html>
    <head>
      <title>Using itemref for meta in the head</title>
      <meta itemprop="datePublished" content="2011-03-25" id="date">
    </head>
    <body>
    
      <div itemscope itemtype="http://schema.org/Review" itemref="date">
        <span itemprop="name">…</span>
      </div>
    
    </body>
    </html>
    

    itemref 采用空格分隔的id 值列表,因此您甚至可以引用两个或更多元素。只需将应添加到项目的所有元素(包含itemprop 属性)的id 添加到其itemref 属性中,例如:itemref="date author rating"

    【讨论】:

    【解决方案2】:

    还请记住,可以完全避免 HTML 标记并使用 JSON-LD 标记完全包含在 &lt;head&gt; anywhere in the HTML document (even dynamically injected!) 中,如下所示:

    <script type="application/ld+json">
    {
      "@context": "http://schema.org",
      "@type": "Restaurant",
      "name": "Fondue for Fun and Fantasy",
      "description": "Fantastic and fun for all your cheesy occasions",
      "openingHours": "Mo,Tu,We,Th,Fr,Sa,Su 11:30-23:00",
      "telephone": "+155501003333",
      "menu": "http://example.com/menu"
    }
    </script>
    

    看看schema.org中的示例,它们通常包含像https://schema.org/Restaurant这样的JSON示例标记。

    这是另一篇关于它的好文章http://www.seoskeptic.com/json-ld-google-knowledge-graph-schema-org-seo/

    【讨论】:

      【解决方案3】:

      我可以从 whatwg.org 读到在正文中使用是正确的:http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#the-meta-element

      我在博客正文中使用元标记来指定“datePublished”和“dateUpdated”属性。 Googles Rich Snippets Testing Tool 告诉我它是正确的,并且 w3c 验证了代码。

      【讨论】:

      • Erik 的经历反映了我自己的经历。为了让丰富的 sn-p 测试工具识别它们,我不得不将它们移动到身体上。我们在 Google 中的搜索结果显示它们正确提取,因为我们在结果中看到了这些属性。
      • dateUpdated 在此页面上不再存在 http://schema.org/docs/full.html
      【解决方案4】:

      你可以使用:

      <meta itemprop="">
      

      在页面的正文中进行机器可读的 schema.org 语义标记(例如,通过机器人,用于 SEO),即使您不想在其上显示实际文本(例如产品名称)页面。

      见:http://schema.org/docs/gs.html#advanced_missing

      有时,网页包含有价值的信息 up,但信息不能被标记,因为它的方式 出现在页面上。信息可以在图像中传达(例如 例如,用于表示 4 分(满分 5 分)的图像或 Flash 对象(例如,视频剪辑的持续时间),或者它可能是 暗示但未在页面上明确说明(例如, 价格的货币)。

      【讨论】:

      • 别忘了在元标记上使用内容!
      【解决方案5】:

      我是这样做的:

      <meta id="md_course" itemprop="course" name="course"   content="..."/>
      <meta id="md_lang" itemprop="language" content="eng"/>
      <title id="md_title" itemprop="title" >Motivation and Course Overview</title>
      </head>
      <body itemscope itemtype=".../Presentation" itemref="md_course md_lang md_title md_field"> 
      

      【讨论】:

      • 根据 Schema.org ,当你在元标记上使用 itemprop 时,你应该省略 name & ... 并且只使用 itemprop & content :)
      • not validmeta 上有一个itemprop 一个name 属性。要么是要么。 (这直接来自 Microdata,而不是(仅)来自 Schema.org 词汇表。)
      【解决方案6】:

      第一次使用 schema.org 的微数据时,我在网页的 head 标记中添加了元标记,但是当我针对 Google's Rich Snippets Testing Tool 运行该页面时,没有提取数据。然后我将元标记移动到页面的正文中,数据显示为被提取。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-26
        • 1970-01-01
        • 1970-01-01
        • 2016-05-30
        • 2019-06-17
        相关资源
        最近更新 更多