-
Hello:
We are using Stamped as review collector on our website along with rankmath suite. When we test the data from Google structure data tools & Rich results are getting error message on “aggregateRating” & “review” fields.
When i contacted Stamped they shared the attached file to be replaced and the below script to be added to footer. Although i do not want to change the source file of Rankmath plugin as once i upgrade those changes would be lost and it would be a tough task to get it back again up and running.
1.In this location, please update the class-product.php (attached in this ticket)
/wp-content/plugins/seo-by-rank-math/includes/modules/rich-snippet/snippets
2.In WooCommerce footer, please add these JS script:<script> function addEventListenerStamped(el, eventName, handler) { if (el.addEventListener) { el.addEventListener(eventName, handler); } else { el.attachEvent('on' + eventName, function () { handler.call(el); }); } } addEventListenerStamped(document, 'stamped:reviews:loaded', function(e) { var ratingCount = jQuery('meta[itemprop="reviewCount"]').attr('content'); var ratingValue = jQuery('meta[itemprop="ratingValue"]').attr('content'); var richSnippet = { "@id": location.href + '#product', "@context": "http://schema.org", "@type": "Product" } if (parseInt(ratingValue) > 0){ richSnippet.aggregateRating = { "@type": "AggregateRating", "ratingValue": ratingValue, "reviewCount": ratingCount } } var script = document.createElement('script'); script.type = 'application/ld+json'; script.innerHTML = JSON.stringify(richSnippet); document.getElementsByTagName('head')[0].appendChild(script); }); </script>
Is there some solution Rankmath team can offer so it works out of the box?
Regards
The ticket ‘Stamped aggregate rating & review error’ is closed to new replies.