2

I'm trying to markup some HTML with schema.org microdata, however I'm getting an issue with my markup:

Here's my current HTML:

<div>
    <h1>
        <a href="example.com/1234">The name is here</a>
        <small>(Some extra info)</small>
    </h1>
    Tons more content about the thing
</div>

What I want to do is describe the existence of the thing and its name and tried:

<div itemscope itemtype="http://schema.org/Thing">
    <h1>
        <a href="example.com/1234" itemprop="name">The name is here</a>
        <small>(Some extra info)</small>
    </h1>
    Tons more content about the thing
</div>

But that gives me this incorrect metadata:

enter image description here

<div itemscope itemtype="http://schema.org/Thing">
    <h1 itemprop="name">
        <a href="example.com/1234">The name is here</a>
        <small>(Some extra info)</small>
    </h1>
    Tons more content about the thing
</div>

But this is also incorrect as it incorrectly identifies (Some extra info) as part of the name (which it isn't):

enter image description here

In conclusion, is there a way to apply itemprop to an <a href=> link without it using the URL as the value for the property?

1 Answers1

2

Microdata does not provide a way to denote that an itemprop on an a element should not produce a URL as value.

You have to add another element that

  • is one of the elements that produces string values in Microdata (tl;dr: not time and not one of the elements that can have a href/src attribute), and

  • only contains the content that you want to have as value of the property.

In your example, you could add a span element:

<a href="example.com/1234"><span itemprop="name">The name is here</span></a>
<span itemprop="name"><a href="example.com/1234">The name is here</a></span>
Community
  • 1
  • 1
unor
  • 92,415
  • 26
  • 211
  • 360
  • Dang, is there a way that doesn't include introducing redundant elements, or can you give a link that supports this? I thought this was the case, but would like to read about it in the docs so I'm not bitten again. –  Jun 17 '15 at 01:09
  • @LegoStormtroopr: [My answer](http://stackoverflow.com/a/27871012/1591669) I linked to shows which HTML5 elements produce which value. This is based on the Microdata section [Values](http://www.w3.org/TR/2013/NOTE-microdata-20131029/#values), which specifies an algorithm to decide what the value of a property must be. Your example would be the fourth case: "If the element is an `a` […] element […] The value is the absolute URL". – unor Jun 17 '15 at 01:15
  • Double dang it. But, thanks for your answer :) Now I know. –  Jun 17 '15 at 01:17