I’m trying to add my Yotpo review ratings to my product schema

Hi everyone! I’m trying to add my Yotpo review ratings to my product schema. Currently, my theme uses the standard {{- product | structured_data -}} filter to generate JSON-LD.

Since I can’t edit the code inside that filter, I need help adding a second script block for the Yotpo aggregateRating metafields so that Google can see my star ratings.

I’ve located the file (sections –> main.product-liquid), but I want to make sure I place the new script tag in the correct spot (right after the Shopify block) without causing any syntax errors or breaking the containers. Could someone guide me on exactly where to drop the Yotpo snippet? Thanks!

Make sure it’s not output already – many apps integrate with this filter by supplying necessary data.

Otherwise your choices are basically explained here – Product - Supplemental Schema Markup - #2 by tim_1
Extending existing JSON-LD can be done like here – Liquid/Schema Help: Mapping Custom Shipping/Return Metafields to Google's Structured Data - #3 by tim_1

So the combined code should be like this:

<script type="application/ld+json">
  {{ product | structured_data }}
</script>

{% #  the below can be added in a "Custom Liquid" block to avoid theme code edits %}

{% if product.metafields.yotpo.reviews_count and product.metafields.yotpo.reviews_count > 0 %}
 <script type="application/ld+json">
  {
    "@context": "http:\/\/schema.org\/",
    "@id": {{ product.url | append: '#product' | json }},
    "@type": "Product",
    "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": {{ product.metafields.yotpo.reviews_average }},
        "reviewCount": {{ product.metafields.yotpo.reviews_count }}
      }
  }
 </script>
{% endif %}

This code should extend your main JSON-LD because it uses the same @id

1 Like

thank you so much!

i followed the steps of the id-solution. although when i run a test on a specific product page in google search, it still shows that the review and aggregate rating are missing… do you know how i can fix this? :slight_smile:
thank you!

Can you share a link to one to those pages so I can have a look?

Custom shipping solution validated just fine, so this should too, just need to have a look at the actual page.
Can DM me if not keen to share publicly.

Hi there,

sure! I can’t seem to find the dm button, so here’s a link to one of our product pages: NO. 5 TAN MOUSSE – Boë Beauté (the one that i’ve been running through google search).

Let me know if you need anything else - and thanks again! :slight_smile:

ok, I see this:

  1. There is a “liquid error” message produced by my code.

    This can be fixed. Try this code instead:
<script type="application/ld+json">
  {{ product | structured_data }}
</script>

{% #  the below can be added in a "Custom Liquid" block to avoid theme code edits %}

{% if product.metafields.yotpo.reviews_count %}
  {% assign reviews_count = product.metafields.yotpo.reviews_count.value | plus: 0  %}
  {% if reviews_count > 0 %}
    <script type="application/ld+json">
      {
        "@context": "http:\/\/schema.org\/",
        "@id": {{ product.url | append: '#product' | json }},
        "@type": "Product",
        "aggregateRating": {
            "@type": "AggregateRating",
            "ratingValue": {{ product.metafields.yotpo.reviews_average }},
            "reviewCount": {{ product.metafields.yotpo.reviews_count }}
          }
      }
    </script>
  {% endif %}
{% endif %}
  1. However, it looks like Yotpo outputs its own structured data for Product, which includes the reviews.
    It could be good and an option would be to remove the theme own structured data, but look at this – it does not properly convert currencies:

    I am in Australia, so theme shows me AU$40 (which is approximately EUR24) and theme own structured data has "price":"40.00","priceCurrency":"AUD"
    while Yotpo shows EUR40 – "price": "40.0","priceCurrency": "EUR"

Other than that, Yotpo snippet looks fine.

I am not sure if it is possible to disable structured data in Yotpo.
If not, you’d need to force them to fix currency conversion issue.
When they do, simply remove the

<script type="application/ld+json">
  {{ product | structured_data }}
</script>

from the theme code and let Yotpo handle your structured data.

Or, try my amended code to extend the theme structured data and disable Yotpos one.

1 Like

It looks like it works with the amended code!! :smiley:
I’ve also messaged yotpo to get them to look at the conversion/currency-issue - thank you for bringing that to my attention as well!

thank you so much for your help! It’s truly appreciated and deeply valued :slight_smile:

1 Like

Great solution by @tim_1. Just a quick heads-up for anyone implementing this: always double-check your Google Search Console (Rich Results test) after manual JSON-LD edits.

Using multiple Product blocks can sometimes lead to ‘AggregateRating’ conflicts if the theme already outputs its own schema. It’s a common issue when mixing third-party review apps with custom Liquid code. Make sure to validate the output to ensure your SEO snippets don’t disappear from Google !