Varaible as a Rich Snippet ratingValue

#268082
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting the support, and sorry for any inconvenience that might have been caused due to that.

    The GUI will only accept numbers for the ratingValue as the Rich Result will expect numerical value for this but if you do need to modify it, you can do this by filter instead. Please refer to this filter:

    /**
     * Filter to change the schema data.
     * Replace $schema_type with schema name like article, review, etc.
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( 'rank_math/snippet/rich_snippet_{$schema}_entity', function($entity) {
        $entity['review']['reviewRating'] = [
            '@type' => 'Rating',
    		'ratingValue' => "your_review_rating"
        ];
        return $entity;
    });

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thank you Jeremy,

    I was able to come with the following code to fit my needs, maybe someone will reuse it in future!

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function($entity) {
        $score = get_post_meta(get_the_ID(), 'your_custom_field', TRUE);
        #$entity['review']['reviewRating']['ratingValue'] = $score; #only update a single rating value
        $entity['review']['reviewRating'] = [
            '@type' => 'Rating',
            'ratingValue' => $score,
            'bestRating' => '10'
        ];
        return $entity;
    });

    Hello,

    We’re glad that you were able to resolve the issue.

    If you have another question in the future, please feel free to reach out, and it will be our pleasure to assist you again.

    Thank you.

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

The ticket ‘Varaible as a Rich Snippet ratingValue’ is closed to new replies.