How do you use link text as value in schema.org value?

329 Views Asked by At

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

There are 1 best solutions below

3
On BEST ANSWER

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>