Add aggregateRating to rich snippets

#137197
  • I would like to add aggregateRating via functions.php

    This is the example code I am using:

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    	$entity['aggregateRating'] = '{"@type":"AggregateRating","ratingValue":"5","bestRating":"5","worstRating":"1","ratingCount":"2"}';
    	return $entity;
    });

    It adds the code to the rich snippet, but also adds slashes to the quotation marks, so my rich snippet looks like:
    "aggregateRating":"{\"@type\":\"AggregateRating\",\"ratingValue\":\"5\",\"bestRating\":\"5\",\"worstRating\":\"1\",\"ratingCount\":\"2\"}"

    Is this solvable?

Viewing 2 replies - 1 through 2 (of 2 total)
  • After posting my question I found the solution:

    $entity['aggregateRating']['@type'] = 'AggregateRating';
    $entity['aggregateRating']['ratingValue'] = '5';
    $entity['aggregateRating']['bestRating'] = '5';
    $entity['aggregateRating']['worstRating'] = '1';
    $entity['aggregateRating']['ratingCount'] = '2';

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    We are glad it worked for you.

    If you have any other concerns, please don’t hesitate to contact us anytime by creating a new ticket to assist you further with anything else.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

The ticket ‘Add aggregateRating to rich snippets’ is closed to new replies.