0

I'm busy adding microdata (schema.org) to a website about a software application.

Instead of repeating myself in terms of duplicate code I try to add metadata one time (where possible) and reference to it.

This is where I still having questions:

How do you properly reference to other metadata without the metadata being added to the page itself? Let me give an example: first I tried this:

<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/WebSite" lang="en">
<body itemprop="mainEntity" itemscope itemtype="http://schema.org/WebPage">
    <div class="main">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <!-- info about product and reference to the metadata -->
                <div itemscope itemtype="http://schema.org/SoftwareApplication" itemref="microdataMyProduct1">
                    <!-- product info on website -->
                </div>
                </div>
            </div>
        </div>
    </div>

<!-- this metadata gets also added to the WebPage -->
  <div id="microdataMyProduct1">
    <meta itemprop="name" content="My Product 1" />
    </div>
</body>
</html>

But this code above adds also the microdata itemprop's of the product to the scope of the "WebPage". (where google testing tool complains about, because some itemprop's from 'SoftwareApplication' are not valid for 'WebPage')

So I thought to add an item scope and replace these lines:

<div itemscope itemtype="http://schema.org/SoftwareApplication" itemref="microdataMyProduct1"> 
<!-- ... -->
<div id="microdataMyProduct1">
<!-- ... -->

with these lines:

<div itemscope itemtype="http://schema.org/SoftwareApplication" itemref="microdataMyProduct1">
<!-- ... -->
<div itemscope itemtype="http://schema.org/SoftwareApplication" id="microdataMyProduct1">
<!-- ... -->

The problem is that I now have two itemscopes/itemtypes. Is this correct? On another stackoverflow post I've read that you should not use itemref in combination with ID's but reference to an external url. I'm confused.

Here is an example I have now (referencing to several other metadata using itemref (from inside the head and in microdata itself):

<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/WebSite" lang="en">
<head>
  <meta name="author" content="Company 1">
  <meta itemprop="author" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1">
  <meta itemprop="about" itemscope itemtype="http://schema.org/SoftwareApplication" itemref="microdataMyProduct1">
  <!-- ... -->
</head>
<body itemprop="mainEntity" itemscope itemtype="http://schema.org/WebPage">
  <div itemprop="hasPart" itemscope itemtype="http://schema.org/WPHeader">
    <nav class="navbar" itemprop="hasPart" itemscope itemtype="http://schema.org/SiteNavigationElement">
        <!-- ... -->
    </nav>
  </div>

    <div class="main">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <!-- another second product on the page -->
                <div itemscope itemtype="http://schema.org/SoftwareApplication">
                    <h3 itemprop="name">Second Product</h3>
                    <meta itemprop="applicationCategory" content="BusinessApplication" />
                    <meta itemprop="creator" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
                    <meta itemprop="producer" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
                    <meta itemprop="provider" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataOtherCompany" />
                    <!-- ... -->
                </div>
                </div>
            </div>
        </div>
    </div>

    <div class="footer" itemprop="hasPart" itemscope itemtype="http://schema.org/WPFooter">
    </div>


  <!-- Product 1 microdata -->
<!-- ##################### -->
  <div hidden class="hidden" itemscope itemtype="http://schema.org/SoftwareApplication" id="microdataMyProduct1">
    <meta itemprop="name" content="My Product 1" />
    <meta itemprop="applicationCategory" content="BusinessApplication" />
    <meta itemprop="creator" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
    <meta itemprop="producer" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
    <meta itemprop="provider" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataOtherCompany" />
    </div>

<!-- Company 1 microdata -->
<!-- ################### -->
    <div hidden class="hidden" itemscope itemtype="http://schema.org/LocalBusiness" id="microdataCompany1">
      <meta itemprop="name" content="Company 1">
        <!-- ... -->
      <div itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/OpeningHoursSpecification">
        <link itemprop="dayOfWeek" href="http://schema.org/Monday" />
        <time itemprop="opens" content="8:00:00" />
        <time itemprop="closes" content="12:30:00" />
        <time itemprop="opens" content="13:30:00" />
        <time itemprop="closes" content="18:00:00" />
      </div>
      <div itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/OpeningHoursSpecification">
        <link itemprop="dayOfWeek" href="http://schema.org/Tuesday" />
        <time itemprop="opens" content="8:00:00" />
        <time itemprop="closes" content="12:30:00" />
        <time itemprop="opens" content="13:30:00" />
        <time itemprop="closes" content="18:0:00" />
      </div>
    </div>

<!-- Other Company  microdata -->
<!-- ######################## -->
    <div hidden class="hidden" itemscope itemtype="http://schema.org/LocalBusiness" id="microdataOtherCompany">
      <meta itemprop="name" content="Other Company">
      <meta itemprop="legalName" content="Other Company Ltd.">
      <div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
        <meta itemprop="streetAddress" content="FooStreet">
        <!-- ... -->
      </div>
    </div>
</body>
</html>

Is this correct usage of microdata for a page on a website about a product? Are itemref="" attributes correctly used?

juFo
  • 17,849
  • 10
  • 105
  • 142
  • Related: [How to split itemscope over multiple HTML elements?](http://stackoverflow.com/q/29135360/1591669) – unor Jan 26 '17 at 16:48

1 Answers1

0

You shouldn't duplicate itemscope for reffering and reffered element. The correct usage will be like this:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta name="author" content="Company 1">
</head>
<body>
<main itemprop="mainEntity" itemscope itemtype="http://schema.org/WebPage">
  <div itemprop="hasPart" itemscope itemtype="http://schema.org/WPHeader">
    <nav class="navbar" itemprop="hasPart" itemscope itemtype="http://schema.org/SiteNavigationElement">
    </nav>
  </div>
  <div class="main">
    <div class="container">
      <div class="row">
        <div class="col-md-12">
          <div itemscope itemtype="http://schema.org/SoftwareApplication" itemref="microdataMyProduct1">
          </div>
          <!-- another second product on the page -->
          <div itemscope itemtype="http://schema.org/SoftwareApplication">
            <h3 itemprop="name">Second Product</h3>
            <meta itemprop="applicationCategory" content="BusinessApplication" />
            <meta itemprop="creator" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
            <meta itemprop="producer" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
            <meta itemprop="provider" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataOtherCompany" />
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="footer" itemprop="hasPart" itemscope itemtype="http://schema.org/WPFooter">
  </div>
</main>
  <!-- Product 1 microdata -->
  <!-- ##################### -->
  <div hidden class="hidden" id="microdataMyProduct1">
    <meta itemprop="name" content="My Product 1" />
    <meta itemprop="applicationCategory" content="BusinessApplication" />
    <meta itemprop="creator" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
    <meta itemprop="producer" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
    <meta itemprop="provider" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataOtherCompany" />
    <meta itemprop="image" content="http://example.com/example.gif" />
  </div>
  <!-- Company 1 microdata -->
  <!-- ################### -->
  <div hidden class="hidden" id="microdataCompany1">
    <meta itemprop="name" content="Company 1">
    <meta itemprop="image" content="http://example.com/example.gif" />
    <div itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/OpeningHoursSpecification">
      <link itemprop="dayOfWeek" href="http://schema.org/Monday" />
      <time itemprop="opens" content="8:00:00" />
      <time itemprop="closes" content="12:30:00" />
      <time itemprop="opens" content="13:30:00" />
      <time itemprop="closes" content="18:00:00" />
    </div>
    <div itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/OpeningHoursSpecification">
      <link itemprop="dayOfWeek" href="http://schema.org/Tuesday" />
      <time itemprop="opens" content="8:00:00" />
      <time itemprop="closes" content="12:30:00" />
      <time itemprop="opens" content="13:30:00" />
      <time itemprop="closes" content="18:0:00" />
    </div>
  </div>
  <!-- Other Company  microdata -->
  <!-- ######################## -->
  <div hidden class="hidden" id="microdataOtherCompany">
    <meta itemprop="name" content="Other Company">
    <meta itemprop="image" content="http://example.com/example.gif" />
    <meta itemprop="legalName" content="Other Company Ltd.">
    <div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
      <meta itemprop="streetAddress" content="FooStreet">
    </div>
  </div>
</body>
</html>
br3t
  • 1,646
  • 2
  • 20
  • 27
  • 1
    are you sure? because now you add properties of "microdataMyProduct1" to WebPage. This generates errors like "applicationCategory: BusinessApplication (Google doesn't recognize the property applicationCategory for an object of type WebPage). you can test your code fragment: https://search.google.com/structured-data/testing-tool you are facing the problem now that I mentioned in my post... – juFo Jan 25 '17 at 10:05
  • Ok, I've edited code. `WebSite` is removed, `WebPage` is relocated. – br3t Jan 25 '17 at 10:30
  • this is a temp fix as other objects might be added/nested resulting in the same issue... – juFo Jan 25 '17 at 10:51
  • Just don't put your reffered parts into `WebPage`-wrapper. – br3t Jan 25 '17 at 11:00
  • before I give you the answer I want to wait if there is another solution possible. – juFo Jan 25 '17 at 14:35