Add Schema.org Review Markup to Your Site

By now, you’ve likely heard all of the hype surrounding structured data and the benefits of including it on your webpages, namely the fact that it has the potential to increase the amount of traffic that is driven to your site.

To illustrate, here’s a Google search results entry of a page that does not include any structured data:

Search Result without Structured Data
Search Result without Structured Data

And here’s a Google search results entry of a page that does include structured data:

Search Result with Structured Data
Search Result with Structured Data

Which one are you more likely to click on?

Add Schema.org Review Markup

I wanted to add structured data to my WordPress Book Review Plugin which, incidentally, is what my book blog uses. In particular, I wanted to add schema.org markup so that posts would show up with the rating, author, and published date in search results pages.

So I marked up the HTML using the Book, PersonReview and Rating schemas. The relevant bits looked a little something like this:

<div itemscope itemtype="http://schema.org/Book">
  <span itemprop="author" itemscope itemtype="http://schema.org/Person">
    <span itemprop="name">
      <?php echo $book_review_author ?>
    </span>
  </span>
  <br>
  <meta itemprop="datePublished" content="<?php date( 'Y-m-d',
    strtotime( $book_review_release_date ) ) ?>">
  <span>
    <?php echo $book_review_release_date ?>
  </span>
  <br>
  <div itemprop="review" itemscope itemtype="http://schema.org/Review">
    <div itemprop="reviewRating" itemscope
      itemtype="http://schema.org/Rating">
      <meta itemprop="ratingValue"
        content="<?php echo $book_review_rating ?>">
      <img src="<?php echo $book_review_rating_url ?>" />
      <br>
    </div>
  </div>
</div>

I ran one of my pages through Google’s Structured Data Testing Tool, but the rating, author and published date were not showing in the preview, even though they were showing in the Extracted structured data section (there’s also a newer version of the Testing Tool, but I prefer the old one since the new doesn’t show a rich snippets preview as of yet):

Structured Data Testing Tool - Extracted structured data
Structured Data Testing Tool – Extracted structured data

I ended up eliminating the use of the Book schema altogether and just used the Review schema. As a test, I marked up the rating by itself:

<div itemscope itemtype="http://schema.org/Review">
  <!-- More HTML goes here. -->
  <div itemprop="reviewRating" itemscope
    itemtype="http://schema.org/Rating">>
    <meta itemprop="ratingValue"
      content="<?php echo $book_review_rating ?>">
    <img src="<?php echo $book_review_rating_url ?>" />
    <br>
  </div>
</div>

Still no joy. This made no sense. I should definitely be seeing a star rating in the testing tool by now!

Google Webmaster Tools

After some googling, I found that I could utilize the Google Webmaster Tools to see the structured data types that Google had found on my site. (Note: This section can be found under Search Appearance > Structured Data.)  That sounded pretty awesome, but it turns out that Google wasn’t finding any data yet. Although frustrating, that made sense since Google hadn’t had time to crawl my site in order to pick up my latest changes. So this tool wasn’t going to be able to help me debug.

The Solution

After a bit of trial & error and trying various combinations, I finally figured out what the problem was – the author property is required! I ended up with the following structure in the end:

<div itemscope itemtype="http://schema.org/Review">
  <meta itemprop="author" content="<?php echo get_the_author(); ?>">
  <meta itemprop="datePublished" content="<?php the_date( 'Y-m-d' ); ?>">
  <div itemprop="reviewRating" itemscope
    itemtype="http://schema.org/Rating">
    <meta itemprop="ratingValue"
      content="<?php echo $book_review_rating ?>">
    <img src="<?php echo $book_review_rating_url ?>" />
    <br>
  </div>
</div>

Finally, my post was showing up as I had expected it to in the testing tool:

Structured Data Testing Tool - Preview
Structured Data Testing Tool – Preview

The fact that the author property is mandatory was confirmed a few days later when I checked the structured data in the Webmaster Tools. I guess in the couple days it took me to resolve the issue, Google had crawled some of the pages on my site that had faulty structured data:

Google Webmaster Tools - "Missing: author" Error
Google Webmaster Tools – “Missing: author” Error

Now, I’m seeing more and more of my pages show up without any errors, and when I search for them in Google, sure enough they are showing up there as well, complete with ratings, author and published date.

Here’s hoping this saves someone else an endless amount of frustration when adding schema.org markup to their own pages!