Last active
December 20, 2024 08:37
-
-
Save wp-seopress/7e98d6c739ef7551d5a29008d692a556 to your computer and use it in GitHub Desktop.
Integrate KK Star Ratings with SEOPress PRO schemas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This snippet will retrieve the votes from the current post handled by KK Star Ratings plugin | |
add_filter('seopress_schemas_auto_recipe_json', 'sp_schemas_auto_recipe_json'); | |
function sp_schemas_auto_recipe_json($json) { | |
$post_id = get_the_ID(); | |
$rating_data = get_post_meta($post_id, '_kksr_avg_default', true); | |
$count = get_post_meta($post_id, '_kksr_count_default', true); | |
if (!empty($rating_data) && !empty($count)) { | |
$json['aggregateRating'] = [ | |
'@type' => 'AggregateRating', | |
'ratingValue' => $rating_data, | |
'reviewCount' => $count | |
]; | |
} | |
return $json; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment