Can I Use Multiple ItemProps in a Span Tag for schema.org Rich Snippets?

痴心易碎 提交于 2019-11-26 09:46:55

问题


Let\'s say I have the following sentence I want to add rich snippets to:

I live and work in New York

Since New York is both my residency and the city where I work in, I would theoretically want to tag the line like this using schema.org standards:

<div itemscope itemtype = \'http://schema.org/Person\'>I live and work in 
<span itemprop = \'homeLocation\'  itemprop = \'workLocation\'>New York</span></div>

Is it valid to have 2 itemprops in one span tag? If not, will the below work?

<div itemscope itemtype = \'http://schema.org/Person\'>I live and work in 
<span itemprop = \'homeLocation\'><span itemprop = \'workLocation\'>New York
</span></span></div>

回答1:


The usual HTML way would be to use one attribute and separate several values with space characters.

Looking into the Microdata specification, you’ll notice that this is the case for the itemprop attribute, too:

The itemprop attribute, if specified, must have a value that is an unordered set of unique space-separated tokens […]

So this should be correct:

<div itemscope itemtype="http://schema.org/Person">
  I live and work in <span itemprop="homeLocation workLocation">New York</span>
</div>

(Note: If using itemprop values as CSS selector, use [att~=val] instead of [att=val].)




回答2:


The first snippet of code I posted does not work, but the second does. Google has a rich snippets page tester which is pretty useful for code validation



来源:https://stackoverflow.com/questions/14198956/can-i-use-multiple-itemprops-in-a-span-tag-for-schema-org-rich-snippets

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