• Resolved Elementardesign

    (@elementardesign)


    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&#8221; . ‘” 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&#8221;
    $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”>&#8217;
    . ‘<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

    https://www.ads-software.com/plugins/multi-rating/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author dpowney

    (@dpowney)

    Hi Isabelle,

    The “mr_rating_result_product_microdata” filter does not exist. It needs to be changed to “mr_rating_result_microdata”.

    Modifying the rating-result.php template file is a perfectly fine approach though. If you follow the steps here danielpowney.com/docs/template-system/ the template file will not be overridden on future plugin updates.

    Thanks,
    Daniel

    Thread Starter Elementardesign

    (@elementardesign)

    Hi Daniel,

    thanks a lot! I followed the steps on your homepage and it works perfectly!

    All the best
    Isabelle

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Structured Data Typ change from Article to Product’ is closed to new replies.