Bug in schema code
-
Hi, I would like to report a bug for your plugin on schema.org structured data. Aggregate Rating show an error with the newest Google schema update.
So everybody who uses show_rich_snippets=true will experience this.
Hopefully you can fix this soon,
Best,
Milan
-
Please fix this! As Milan said Google doesn’t show anything (ratings).
Hi @milannikolic @comicschau ,
Thanks for reporting this bug. Some recent Google changes has broken the review and aggregate rating microdata in the free and premium versions of the Multi Rating plugin. A specific item type is now required for reviews whereas previously a generic https://schema.org/Thing item was used. See here https://webmasters.googleblog.com/2019/09/making-review-rich-results-more-helpful.html
There is a quick fix for the following items:
– https://schema.org/Product
– https://schema.org/Organization
– https://schema.org/MusicRecording
– https://schema.org/MusicPlaylist
– https://schema.org/MediaObject
– https://schema.org/Game
– https://schema.org/Episode
– https://schema.org/CreativeWorkSeries
– https://schema.org/CreativeWorkSeasonAdd the following code to your theme functions.php file and replace https://schema.org/Product with your item type.
function my_microdata_fix( $microdata, $post_id ) { $microdata = '<span itemprop="itemReviewed" itemscope itemtype="https://schema.org/Product">' . '<meta itemprop="name" content="' . get_the_title( $post_id ) . '" />' . '</span>'; return $microdata; } add_filter( 'mr_microdata_aggregate_rating_item_reviewed', 'my_microdata_fix', 10, 2 );
For the premium version, the only difference is the prefix of the filter name (mrp_ instead of mr_).
For https://schema.org/Recipe and https://schema.org/LocalBusiness items, an image property is also required. We can add the post thumbnail image for example:
function my_microdata_fix( $microdata, $post_id ) { $microdata = '<span itemprop="itemReviewed" itemscope itemtype="https://schema.org/Recipe">' . '<meta itemprop="name" content="' . get_the_title( $post_id ) . '" />' . '<meta itemprop="image" content="' . get_the_post_thumbnail_url( $post_id ) . '" />' . '</span>'; return $microdata; } add_filter( 'mr_microdata_aggregate_rating_item_reviewed', 'my_microdata_fix', 10, 2 );
The following item types require many properties specific to the type of item. So there is no quick fix for these items unfortunately.
– https://schema.org/SoftwareApplication
– https://schema.org/Movie
– https://schema.org/HowTo
– https://schema.org/Event
– https://schema.org/Course
– https://schema.org/Book- This reply was modified 5 years, 2 months ago by dpowney.
Hi @milannikolic @comicschau ,
Thanks for reporting this bug. Some recent Google changes has broken the review and aggregate rating microdata in the free and premium versions of the Multi Rating plugin. A specific item type is now required for reviews whereas previously a generic https://schema.org/Thing item was used. See here https://webmasters.googleblog.com/2019/09/making-review-rich-results-more-helpful.html
There is a quick fix for the following items:
– https://schema.org/Product
– https://schema.org/Organization
– https://schema.org/MusicRecording
– https://schema.org/MusicPlaylist
– https://schema.org/MediaObject
– https://schema.org/Game
– https://schema.org/Episode
– https://schema.org/CreativeWorkSeries
– https://schema.org/CreativeWorkSeasonAdd the following code to your theme functions.php file and replace https://schema.org/Product with your item type.
function my_microdata_fix( $microdata, $post_id ) { $microdata = '<span itemprop="itemReviewed" itemscope itemtype="https://schema.org/Product">' . '<meta itemprop="name" content="' . get_the_title( $post_id ) . '" />' . '</span>'; return $microdata; } add_filter( 'mr_microdata_aggregate_rating_item_reviewed', 'my_microdata_fix', 10, 2 );
For the premium version, the only difference is the prefix of the filter name (mrp_ instead of mr_).
For https://schema.org/Recipe and https://schema.org/LocalBusiness items, an image property is also required. We can add the post thumbnail image for example:
function my_microdata_fix( $microdata, $post_id ) { $microdata = '<span itemprop="itemReviewed" itemscope itemtype="https://schema.org/Recipe">' . '<meta itemprop="name" content="' . get_the_title( $post_id ) . '" />' . '<meta itemprop="image" content="' . get_the_post_thumbnail_url( $post_id ) . '" />' . '</span>'; return $microdata; } add_filter( 'mr_microdata_aggregate_rating_item_reviewed', 'my_microdata_fix', 10, 2 );
The following item types require many properties specific to the type of item. So there is no quick fix for these items unfortunately.
– https://schema.org/SoftwareApplication
– https://schema.org/Movie
– https://schema.org/HowTo
– https://schema.org/Event
– https://schema.org/Course
– https://schema.org/BookH
- This reply was modified 5 years ago by Oliver Nielsen.
- This reply was modified 5 years ago by Oliver Nielsen.
- This reply was modified 5 years ago by Oliver Nielsen.
- This reply was modified 5 years ago by Oliver Nielsen.
It looks like this is now resolved in plugin. Review property now works without any errors.
Thanks
For the technical people, you might like to check out this code snippet to enable JSON-LD rich snippets. I will be looking at replacing the schema.org microdata with JSON-LD in the future.
/** * Adds JSON-LD ratings for schema.org item types */ function mrp_jsonld_ratings() { if ( is_page() || is_single() ) { $post_id = get_queried_object_id(); if ($post_id == null) { return; } // in case you only want to add rich snippets on posts which have auto placement enabled... if ( ! apply_filters( 'mrp_can_apply_auto_placement', true, 'the_title', null, $post_id ) ) { return; } $post_type = get_post_type( $post_id ); $rating_form_id = MRP_Utils::get_rating_form( $post_id ); $rating_result = MRP_Multi_Rating_API::get_rating_result( array( 'post_id' => $post_id, 'rating_form_id' => $rating_form_id ) ); if ($rating_result == null || ($rating_result !== null && $rating_result['count_entries'] === 0)) { return; } $item_type_map = [ "post" => 'Product', "page" => 'Product' ]; $item_type = $item_type_map[$post_type]; $post_title = get_the_title( $post_id ); $post_thumbnail_url = get_the_post_thumbnail_url( $post_id ); $post_excerpt = get_the_excerpt( $post_id ); ?> <script type="application/ld+json"> { "@context": "https://schema.org/", "@type": "<?php echo $item_type; ?>", "name": "<?php echo $post_title; ?>", <?php if ($post_thumbnail_url) { ?> "image": [ "<?php echo $post_thumbnail_url; ?>" ], <?php } if ($post_excerpt) { ?> "description": "<?php echo esc_html($post_excerpt); ?>", <?php } ?> "aggregateRating": { "@type": "AggregateRating", "ratingValue": "<?php echo $rating_result['adjusted_star_result']; ?>", "reviewCount": "<?php echo $rating_result['count_entries']; ?>" } } </script> <?php } } add_action( 'wp_head', 'mrp_jsonld_ratings' );
Hi
No the problem is not resolved !All my snippets works 100 % except the aggregate rating.
Regards
Oliver
- The topic ‘Bug in schema code’ is closed to new replies.