Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

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

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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].)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...