Bug with Structured Data in Rating
-
Hi there,
you have two major bugs to fix in your schema.org implementation. File stars-rating-public.php, line 120 and below.
My suggestion:
public function add_reviews_schema() { if (!self::status()) { return; } $schema_name = ucfirst( get_post_type() ); $schema_title = get_the_title(); $rating_stat = $this->rating_stat(); $review_type = get_option( 'google_search_stars_type' ); if (!empty($review_type)) { $schema_name = esc_attr($review_type); } $rating_value = ($rating_stat['avg']) ? $rating_stat['avg'] : "n/a"; if(intval($rating_stat['count'])> 0) { echo '<script type="application/ld+json"> { "@context": "https://schema.org/", "@type": "AggregateRating", "itemReviewed": "' . $schema_title . '", "ratingValue": "' . $rating_stat['avg'] . '", "bestRating": "5", "ratingCount": "' . intval($rating_stat['count']) . '", "name" : "'.$schema_name.' review" }</script>'; } }
Reason: First of all there are schema.org errors if there are no ratings because values are required. Therefore the if condition. Second thing is, that @type has to be a valid schema.org type like “WebPage” or “Product”, it is not the case for the most post type and a misuse of that property.
Check my implementation suggestion – what do you think? This way it will not conflict with yoast or others.
Validate with: https://search.google.com/structured-data/testing-tool/u/0/?hl=de
Can you fix this?
- The topic ‘Bug with Structured Data in Rating’ is closed to new replies.