As I can undertand I shoud combine all this code below. But I have no idea about how to write this code properly. Can you help me?
global $post;
if( $post->ID == 396 || $post->ID == 396)
{..
+
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
return [];
}, 99, 2);
+
{"@type":"AggregateRating","ratingValue":4.6,"reviewCount":80},"
Thanks!!!
Hello,
Thank you for contacting Rank Math today.
To apply this to your homepage only you need to add the following filter:
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
if ( is_front_page() || ! isset( $data['publisher'] ) ) {
$data['publisher']['aggregateRating']['@type'] = 'AggregateRating';
$data['publisher']['aggregateRating']['ratingValue'] = 4.6;
$data['publisher']['aggregateRating']['reviewCount'] = 80;
}
return $data;
} , 99, 2);
Please note that this might go against Google guidelines because it’s a self-serving review and those are not allowed on this type of Schema: https://developers.google.com/search/docs/advanced/structured-data/review-snippet
Hope this helps solve your issues.
Don’t hesitate to get in touch if you have any other questions.
Thanks for the help and the advice. I have just another question. How can I add this code:
$data['publisher']['aggregateRating']['@type'] = 'AggregateRating';
$data['publisher']['aggregateRating']['ratingValue'] = 4.6;
$data['publisher']['aggregateRating']['reviewCount'] = 80;
on a specific post (not homepage)? I would like to add it to the post with ID = 396.
I found that I may use this code below:
global $post;
if( $post->ID == 396 || $post->ID == 396)
{..
but I have no idea how to write it properly.
Hello,
To apply this to a specific post you can modify the if statement on the filter to something like this:
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
global $post;
if ( $post->ID == 396 ) {
$data['publisher']['aggregateRating']['@type'] = 'AggregateRating';
$data['publisher']['aggregateRating']['ratingValue'] = 4.6;
$data['publisher']['aggregateRating']['reviewCount'] = 80;
}
return $data;
} , 99, 2);
Don’t hesitate to get in touch if you have any other questions.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.