Using HTML5+Microdata's <meta> tag in the <body>

送分小仙女□ 提交于 2019-12-10 13:44:23

问题


I want to specify if the Product is "In Stock" using HTML5+Microdata's <meta> tag using Schema.org.

I am unsure if this is the correct syntax:

<div itemscope itemtype="http://schema.org/Product">
  <h2 itemprop="name">Product Name</h2>
  <dl itemprop="offers" itemscope itemtype="http://schema.org/Offer">
    <dt itemprop="price">$1</dt>
    <meta itemprop="availability" itemscope itemtype="http://schema.org/ItemAvailability" itemid="http://schema.org/InStock">
  </dl>
</div>

回答1:


The meta tag can't be used with an itemscope like that. The correct way to express this is through a canonical reference using the link tag:

<div itemscope itemtype="http://schema.org/Product">
  <h2 itemprop="name">Product Name</h2>
  <dl itemprop="offers" itemscope itemtype="http://schema.org/Offer">
    <dt itemprop="price">$1</dt>
    <link itemprop="availability" href="http://schema.org/InStock">
  </dl>
</div>



回答2:


I did the same as the OP and got the same thing, where the availability on the testing tool is linked to a sub-item... I was finally able to get it to verify properly with this:

<meta itemprop='availability' content='http://schema.org/InStock'>

Here is the Google structured tool output for the offer:

Item 1
type:   http://schema.org/offer
property:   
price:  Price: $139.00
pricecurrency:  USD
availability:   http://schema.org/InStock



回答3:


While it is allowed to use meta (if used for Microdata!) in the body, your example is not correct for several reasons:

  • The dl element can only contain dt or dd (and script/template) elements. You either have to place the meta inside of dt/dd, or outside of dl (but then you would have to move the itemscope).

  • The meta element must have a content attribute.

  • Using itemid for this purpose is not correct, and http://schema.org/ItemAvailability is not a type, so using itemscope+itemtype isn’t correct either.

  • However, if the itemprop value is a URI, you must use the link element instead of the meta element.

Furthermore, the price value should not contain a currency symbol, and it seems that your dt should actually be a dd (with a dt containing "Price" or something).

So you could use:

<dl itemprop="offers" itemscope itemtype="http://schema.org/Offer">
  <dt>Price</dt>
  <dd>$<span itemprop="price">1</span> <link itemprop="availability" href="http://schema.org/InStock" /></dd>
</dl>



回答4:


I made a jsfiddle here: http://jsfiddle.net/dLryX/, then put the output (http://jsfiddle.net/dLryX/show/) into the rich snippets tool.

That came back with:

I believe the syntax is correct, and that the Warning isn't important, as it doesn't have a property, as it's a meta tag.




回答5:


See under the heading Non-visible content (not sure if this helps):

Google webmaster tools - About microdata

In general, Google won't display content that is not visible to the user. In other words, don't show content to users in one way, and use hidden text to mark up information separately for search engines and web applications. You should mark up the text that actually appears to your users when they visit your web pages.

There are a few exceptions to this guideline. In some situations it can be valuable to provide search engines with more detailed information, even if you don't want that information to be seen by visitors to your page. For example, if a restaurant has a rating of 8.5, users (but not search engines) will assume that the rating is based on a scale of 1–10. In this case, you can indicate this using the meta element, like this:

<div itemprop="rating" itemscope itemtype="http://data-vocabulary.org/Rating"> Rating: <span itemprop="value">8.5</span> <meta itemprop="best" content="10" /> </div>




回答6:


This is an example from schema.org's getting started guide to support @Lawrence's answer.

However, I don't like the use of the link tag inside the body of the page. From MDN:

A link tag can occur only in the head element;

Isn't there a better way of specifying availability using a valid markup?



来源:https://stackoverflow.com/questions/7293366/using-html5microdatas-meta-tag-in-the-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!