0

I want to add microdata/rich-snippets to my website but the documentation is pretty unclear about some things, suppose i have this CONCEPTUAL code:

<div itemscope itemtype="http://schema.org/LocalBusiness">
    <div itemprop="name">My Business</div>
    <table itemscope itemtype="http://schema.org/PostalAddress">
        <tr><td itemprop="telephone">0612345678</td></tr>
        <tr><td itemprop="addressCountry">Netherlands</td></tr>
        <-- other postalAdress properties -->
    </table>
</div>

That table obviously holds all the contact properties (and is in a table for formatting reasons). The problem is, that table also holds a telephone number. Google microdata tester thinks that the "telephone" property belongs to PostalAddress, it must however belong to the LocalBusiness. How do i fix this?

user2501247
  • 109
  • 8

1 Answers1

0

Pull the telephone out of the PostalAddress scope:

<div itemscope itemtype="http://schema.org/LocalBusiness">
    <span itemprop="name">My Business</span>
    <span itemprop="telephone">0612345678</span>
    <div itemscope itemtype="http://schema.org/PostalAddress">
        <span itemprop="addressCountry">Netherlands</span>
        <-- other postalAdress properties -->
    </div>
</div

From schema.org:

By adding itemscope, you are specifying that the HTML contained in the <div>...</div> block is about a particular item.

Edit: If you can't change the DOM structure, this is the best I can come up with:

<div itemscope itemtype="http://schema.org/LocalBusiness" itemref="phone">
    <div itemprop="name">My Business</div>
    <table itemscope itemtype="http://schema.org/PostalAddress">
        <tr itemscope><td itemprop="telephone" id="phone">0612345678</td></tr>
        <tr><td itemprop="addressCountry">Netherlands</td></tr>
        <-- other postalAdress properties -->
    </table>
</div>
jeffjenx
  • 17,041
  • 6
  • 57
  • 99
  • That of course is a possibility but it is evading the problem. I have to redo the whole formatting with this approach. There has got to be a simpler solution because this is a typical namespacing problem. – user2501247 Apr 14 '16 at 14:28
  • @user2501247 I added another example, but I think it is uglier and less-understandable. However, that is the only way I can think of to get that property assigned to your LocalBusiness object. Even though it might seem like additional labor to reorganize your DOM structure, I would avoid the table and write it "better" if you have the opportunity. – jeffjenx Apr 14 '16 at 14:42
  • The problem with that solution is that if i have two elements who belong in the parent scope, i have invalid HTML-syntax (two tags with same id). I find it kinda ridiculous that the scoping is so badly supported, this seems like a everyday problem. – user2501247 Apr 14 '16 at 15:10
  • 1
    @user2501247: The `itemref` attributes takes a space-separated list of ID values. So each property gets its own `id`. – unor Apr 14 '16 at 15:23
  • @unor Nice! The only (last) problem i have, is that PostalAddress shares the `itemprop="telephone"`, i do not want the PostalAddress to have a telephone number at all. – user2501247 Apr 14 '16 at 15:30
  • @user2501247: The `itemscope` attribute on the `tr` element should prevent that the `telephone` property gets added to the `PostalAddress` item. – unor Apr 14 '16 at 15:34