12

I'm working with Microdata and I want to use Schema.org’s keywords for CreativeWork.

The schema specifies that it should be text but do I put each keyword in a separate element with itemprop="keywords" or do I put them all in one keywords element? If I put them all in one element do I use commas as a separator?

unor
  • 92,415
  • 26
  • 211
  • 360
Last Rose Studios
  • 2,461
  • 20
  • 30

4 Answers4

13

The definition of Schema.org’s keywords property changed. It now reads:

Keywords or tags used to describe this content. Multiple entries in a keywords list are typically delimited by commas.

So it could look like this in Microdata:

<article itemscope itemtype="http://schema.org/BlogPosting">

  <footer>
    <ul itemprop="keywords">
      <li><a href="/tags/foo" rel="tag">foo</a>,</li>
      <li><a href="/tags/bar" rel="tag">bar</a></li>
    </ul>
  </footer>

</article>

(Example taken from my related answer about semantic markup for tags.)

If you don’t want to have commas visible on the page, you could use a meta element in addition to your normal markup for the tags:

<meta itemprop="keywords" content="foo, bar" />

(It’s allowed to place this meta element in the `body´.)

Community
  • 1
  • 1
unor
  • 92,415
  • 26
  • 211
  • 360
10

You should create an itemprop element for each keyword as follows:

<div itemscope itemtype="http://schema.org/CreativeWork">
  <span itemprop="name">Resistance 3: Fall of Man</span>
  by <span itemprop="author">Sony</span>.
  Keywords:
  <a href="/tags/game/"><span itemprop="keywords">Game</span></a>,
  <a href="/tags/adult/"><span itemprop="keywords">Adult</span></a>
</div>
Lawrence Woodman
  • 1,424
  • 9
  • 13
  • Is it really the right answer? It seemed to me that you can have just one itemprop attribute per property. – Flavio Wuensche Dec 20 '13 at 16:01
  • 1
    @fwuensche: You can have the [same property several times for one item](http://stackoverflow.com/a/22337572/1591669). – unor Mar 28 '14 at 00:05
  • I would add itemprop="url" to both href links. – Jonadabe Apr 10 '14 at 11:30
  • 2
    Everyone reading this right now: this is *NOT* the correct answer, you should follow the answer from unor. This can be confirmed using the google testing tool: https://search.google.com/structured-data/testing-tool/u/0/ – xorinzor Dec 05 '16 at 13:15
4

My reading of the specification leads me to the conclusion that you can have just one itemprop attribute per property.

In other words, i don't think that creating an itemprop element for each keyword will create a correct microdata syntax.

I would put each keyword in a space-separated list, and use a single itemprop:

  <span itemprop="keywords">
  <a href="/tags/game/">Game</a>,
  <a href="/tags/adult/">Adult</a>
  </span>

or

 <meta itemprop="keywords" content="Game Adult"/>

i am not sure what should be done in case a keyword contains multiple words, since there is nothing in the specification that says how keywords should be separated in the text (i assume by spaces and.or punctuation like comma).

@Lawrence Woodman : could you indicate where you read, in the specification, that it is allowed to have multiple itemprop elements for the same property?

  • 1
    I can't follow where you get the information that there's a limit for `just one itemprop attribute per property` in current Microdata draft http://www.w3.org/html/wg/drafts/microdata/master/#property-names Are you referring to property names or property values? The code example states that `the "a" property has the values "1" and "2"`. Moreover the draft specifies if the element is an `a` the value is the URL from its `href` attribute, so your first example would have `keywords: ['/tags/game/', '/tags/adult/']` as name-value pair in my reading. – Volker E. Jul 30 '13 at 14:05
2

By reading the docs, I'd say you can use meta tags to parse content which is whether hidden or in a bad format. That's the case of priceCurrency and datePublished in the code bellow, taken from schema.org documentation.

<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
  Price: <span itemprop="price">$6.99</span>
  <meta itemprop="priceCurrency" content="USD" />
  <link itemprop="availability" href="http://schema.org/InStock">In Stock
</div>

Product details
<span itemprop="numberOfPages">224</span> pages
Publisher: <span itemprop="publisher">Little, Brown, and Company</span> - 
<meta itemprop="datePublished" content="1991-05-01">May 1, 1991
Language: <span itemprop="inLanguage">English</span>
ISBN-10: <span itemprop="isbn">0316769487</span>

Assuming I am right, I've changed my code to the following.

<div itemscope itemtype="http://schema.org/CreativeWork">
  <!-- way too many content -->
  <h5>Keywords</h5>
  <meta itemprop="keywords" content="Rio de Janeiro, Brazil">
  <a href="/tags/rio/" rel="nofollow">Rio de Janeiro</a>
  <a href="/tags/brazil/" rel="nofollow">Brazil</a>
</div>

I'll deploy it in a few days, so sorry I can't tell if it works right now.

UPDATE: After deploying the code, it works like a charm. You can see the results through Google Data Testing Tool and compare to the rich snippets used on the real product.

Flavio Wuensche
  • 9,460
  • 1
  • 57
  • 54