LazNiko
LazNiko

Reputation: 2123

How to add 'name' and 'url' properties to the same tag?

I'm adding the schema.org Microdata to my website.

My HTML code is like this:

<div itemscope itemtype="http://schema.org/Organization">
<span class="title">Name of the organization</span>
<a href="http://www.ABCCompany.com/">ABC Company</a>
</div>

Since the itemprop "url" and "name" of the Organization are all in the anchor tag. How can I indicate the both "url" and "name" itemprop on the same tag? Must I add extra span tag for this purpose?

I have tried searching some coding examples on this but cannot find any example to show the use of multiple itemprop on the same tag.

At the end, I want to have Microdata like this:

url="http://www.ABCCompany.com", name="ABC Company"

Upvotes: 16

Views: 7658

Answers (4)

Mousey
Mousey

Reputation: 1865

This also works and may look a bit easier to maintain:

<div itemscope itemtype="http://schema.org/Organization">
  <span class="title" itemprop="name">
    <a itemprop="url" href="http://www.ABCCompany.com/">ABC Company</a>
  </span>
</div>

Google's support for schema.org and the google structured data tester have improved considerably since the original question was posted. The code above validates correctly in it.

Upvotes: 0

The OP's original code now seems to work ok. As shown here:

https://search.google.com/structured-data/testing-tool#url=http%3A%2F%2Fmercedes-benzhanoi.com.vn%2Fmercedes-ha-noi.auto%2Fgla-250-4matic.html

<div itemscope="" itemtype="http://schema.org/Organization"> <span class="title" itemprop="name"> <a itemprop="url" href="http://mercedes-benzhanoi.com.vn/mercedes-ha-noi.auto/gla-250-4matic.html">GLA 250 4MATIC</a></span> </div>

Upvotes: -1

ole
ole

Reputation: 21

There may be a problem with google. The "rich snippets testing tool" indicates that when you mark an anchor tag as a url, the body of the tag is used as value rather than the href attribute. But nobody wants to display the url inside an anchor tag.

Upvotes: 2

cygri
cygri

Reputation: 9492

You have to do it by nesting two elements. For example, you can nest a <span> inside the <a> and put the itemprop="name" on that:

<div itemscope itemtype="http://schema.org/Organization">
    <a itemprop="url" href="http://www.ABCCompany.com/">
        <span itemprop="name">ABC Company</span>
    </a>
</div>

I find this site handy for testing such things.

Upvotes: 32

Related Questions