review schema integration with Directory plugin

Hi all - first of all thanks for the great work on developing Directory so far, having great fun getting our teeth into customising our latest project.

We've hit a blockade trying to introduce valid schema markup into the review postings, in order to generate correctly indexed Google listings as per review guidelines.

I've started basic, and managed to get some of the more simple fields to append pretty instantly (for instance:

<div class="sr-rate-this" itemprop="aggregateRating"
    itemscope itemtype="">
<span>(<span class="all_votes-<?php echo $post->ID; ?>" itemprop="reviewCount"><?php echo $rating['votes'] ?></span> reviews)</span>

Succesfully returns:

reviewcount: 1

over at Google Structured Data Testing Tool.

I'm currently struggling with assigning ratingValue to my average star rating (key to the look of the listing in Google as it uses this to display the 'stars' on the search result) - of course, when assigned to the following block:

<div class="sr-rate-this" itemprop="aggregateRating"
    itemscope itemtype=""><strong itemprop="ratingValue"><?php _e('Overall:', DR_TEXT_DOMAIN); ?></strong>

All I get returned is the 'Overall:' string, with no rating appended:

ratingvalue: Overall:

I've attempted to look into coding the itemprop variable into the code at a function level - but I can't find anywhere that a flat, numeric variable (1-5) is generated for the rating.

Any help with this would be greatly appreciated - it's the one major tickbox in my opinion that stops this from making the transition to a viable industry choice
for this type of directory site.

Thanks for the hard work guys, over to you! :slight_smile:

  • Ben

    Hey all - me again!

    Further to my last post, I've actually found a pretty rudimentary way around this, by amending the code in ratings.php to the following (around line 256, function render_avg_rating):

    <div class="sr-rate-this" itemprop="aggregateRating"
        itemscope itemtype=""><?php _e('Overall:', DR_TEXT_DOMAIN); ?><strong itemprop="ratingValue" style="display:none;"><?php echo $rating['rating'] ?></strong>

    I simply echoed the already returned array value of 'rating' in a strong tag after the star rating is rendered, with a display:none; (I'll remove this from inline CSS later), and then assigned the itemprop of ratingValue to this new strong tag.

    In this way, the number value does not interfere with the page rendering, but is retained (and dynamically updated) for the purposes of the schema.

    If anybody has any input as to how to improve this, by all means drop by, but I've marked as resolved for now.


  • Ben

    Hey Vaughn, thanks for the welcome and thanks for the reply.

    I couldn't see a hook either, though admittedly my search wasn't extensive - I think a feature request would be fantastic - to be honest, I think it would be more a semantic change e.g. render order and templating changes, rather than extensive development work.

    I've been able to make the schema for reviews work loosely, by adapting some of the template files and running conditional IF statements - for example, I couldn't add the required review name schema to my title element, as the directory page titles were pulled from the header. I wrapped the header code in a simple IF statement that rendered without the h1 tag in header IF the post_type was directory-listing, and instead called the h1 in my listing page template complete with required schema.

    FYI In the case above, it's not possible just to run a conditional IF that renders a revised h1 tag in the header, as it then doesn't appear within the review schema block of the page, and isn't recognised as part of said schema.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.