Structured Data Typ change from Article to Product
-
Hi,
first of all, I like the Multi Rating Plugin a lot! Thanks for this good working free Plugin.
But I have a small problem. I tried to change the Structured Data from the Type “Article” to “Product” via the functions.php in my childtheme. I used and modified your sample-code from here: https://danielpowney.com/docs/code-snippets-api-samples/
But something is wrong with the code and the “AggregateRating”. Google reports errors because the fields “ratingCounts” and “ratingValue” are empty.
Here ist the code from my functions.php:
function mr_rating_result_product_microdata( $microdata, $rating_form_id, $post_id, $rating_result) {
$microdata = ‘<div itemscope itemtype=”‘ . “https://schema.org/Product” . ‘” style=”display: none;”>’;
$post_obj = get_post( $post_id );
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ) );
$image_content = ”;
if ( isset( $image[0] ) ) {
$image_content = $image[0];
}// default required itemprops for “https://schema.org/Article”
$microdata .= ‘<meta itemprop=”description” content=”‘ . $post_obj->post_excerpt . ‘”>’;
$microdata .= ‘<meta itemprop=”name” content=”‘ . $post_obj->post_title . ‘” />’;
$microdata .= ‘<meta itemprop=”image” content=”‘ . $image_content . ‘” />’;// add aggregate rating
$microdata .= ‘<span itemprop=”aggregateRating” itemscope itemtype=”https://schema.org/AggregateRating”>’
. ‘<span itemprop=”ratingValue”>’ . $rating_result[‘adjusted_star_result’] . ‘</span>/<span itemprop=”bestRating”>5</span>’
. ‘<span itemprop=”ratingCount”>’ . $rating_result[‘count’] . ‘</span>’
. ‘</span>’;$microdata .= ‘</div>’;
return $microdata;
}
add_filter( ‘mr_rating_result_microdata’, ‘mr_rating_result_product_microdata’);If I change the code directly in the rating-result.php inside the plugin it works. But this is not good for updates in the future. For now I made the changes in the rating-result.php You can have a look how it should work at the end here: https://www.gruenerakete.de/project/quartiermeister/
Could you help me with this issue?
Thanks in advance
Isabelle
- The topic ‘Structured Data Typ change from Article to Product’ is closed to new replies.