Skip to content

Instantly share code, notes, and snippets.

@wp-seopress
Last active December 20, 2024 08:37
Show Gist options
  • Save wp-seopress/7e98d6c739ef7551d5a29008d692a556 to your computer and use it in GitHub Desktop.
Save wp-seopress/7e98d6c739ef7551d5a29008d692a556 to your computer and use it in GitHub Desktop.
Integrate KK Star Ratings with SEOPress PRO schemas
// 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