{"id":449,"date":"2020-01-19T21:07:06","date_gmt":"2020-01-19T21:07:06","guid":{"rendered":"https:\/\/www.opinew.com\/help-center\/?post_type=ht_kb&#038;p=449"},"modified":"2022-12-30T13:18:27","modified_gmt":"2022-12-30T13:18:27","slug":"displaying-review-rich-snippets-in-shopify","status":"publish","type":"ht_kb","link":"https:\/\/www.opinew.com\/help-center\/knowledge-base\/displaying-review-rich-snippets-in-shopify\/","title":{"rendered":"Displaying review rich snippets in your Shopify store with json ld"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Case 1: No JSON ld included in your theme.<\/h2>\n\n\n\n<p>We have prepared an easy-to-use default JSON ld snippet for you. Paste the ID snippet into your <strong>product.liquid<\/strong> Shopify template. You can ask us for <strong>help via live chat<\/strong> in the bottom right corner of the Opinew Dashboard if required.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">&lt;script>\n     \nvar metafield = String.raw`{{ product.metafields.opinew_metafields['product_plugin'] }}`.replace(\/(\\r\\n|\\n|\\r)\/gm, \"\");\nvar txt = document.createElement(\"textarea\");\ntxt.innerHTML = metafield;\nif (metafield){\n   metafield = JSON.parse(txt.value);\n}\n\nvar opinewJson = {\n  \"@context\": \"http:\/\/schema.org\/\",\n  \"@type\": \"Product\",\n  \"name\": {{ product.title | json }},\n  \"url\": {{ shop.url | append: product.url | json }},\n  {% if product.first_available_variant.barcode.size == 13 %}\n    \"gtin13\":\"{{ product.variants.first.barcode }}\",\n  {% elsif product.first_available_variant.barcode.size == 12 %}\n    \"gtin12\":\"{{ product.variants.first.barcode }}\",\n  {% elsif product.first_available_variant.barcode.size == 8 %}\n    \"gtin8\":\"{{ product.variants.first.barcode }}\",\n  {% endif %}\n  {%- if product.featured_image -%}\n    {%- assign image_size = product.featured_image.width | append: 'x' -%}\n    \"image\": [\n      {{ product.featured_image.src | img_url: image_size | prepend: \"https:\" | json }}\n    ],\n  {%- endif -%}\n  \"description\": {{ product.description | strip_html | json }},\n  {%- if product.selected_or_first_available_variant.sku != blank -%}\n    \"sku\": {{ product.selected_or_first_available_variant.sku | json }},\n  {%- else -%}\n      {% if product.variants.first.sku != blank %}\n        \"sku\": \"{{ product.variants.first.sku }}\",\n      {% else %}\n        \"sku\": \"{{ product.variants.first.id }}\",\n      {% endif %}\n  {%- endif -%}\n  \"brand\": {\n    \"@type\": \"Brand\",\n    \"name\": {{ product.vendor | json }}\n  },\n  {%- if product.metafields.opinew_metafields.reviews_count and product.metafields.opinew_metafields.reviews_count != \"0\" -%} \n\"aggregateRating\": {\n\"@type\": \"AggregateRating\",\n\"ratingValue\": {{ product.metafields.opinew_metafields.reviews_average }},\n\"ratingCount\": {{ product.metafields.opinew_metafields.reviews_count }}\n},\n  \"review\": {\n        \"@type\": \"Review\",\n        \"reviewRating\": {\n          \"@type\": \"Rating\",\n          \"ratingValue\": metafield[\"reviews\"][\"recent\"][0][\"star_rating\"]\n        },\n        \"author\": {\n          \"@type\": \"Person\",\n          \"name\": metafield[\"reviews\"][\"recent\"][0][\"user_name\"]\n        },\n        \"reviewBody\": metafield[\"reviews\"][\"recent\"][0][\"body\"]\n    }, \n{%- endif -%}\n\n  \"offers\": [\n    {%- for variant in product.variants -%}\n      {\n        \"@type\" : \"Offer\",\n        {%- if variant.sku != blank -%}\n          \"sku\": {{ variant.sku | json }},\n        {%- endif -%}\n        \"availability\" : \"http:\/\/schema.org\/{% if product.available %}InStock{% else %}OutOfStock{% endif %}\",\n        \"priceValidUntil\" : \"{{ 'now' | date: '%s' | plus: 31536000 | date: '%Y-%m-%d' | url_encode | replace:'+','%20' }}\",\n        \"price\" : {{ variant.price | divided_by: 100.00 | json }},\n        \"priceCurrency\" : {{ cart.currency.iso_code | json }},\n        \"url\" : {{ shop.url | append: variant.url | json }}\n      }{% unless forloop.last %},{% endunless %}\n    {%- endfor -%}\n  ]\n}\n\nvar el = document.createElement('script');\nel.type = 'application\/ld+json';\nel.text = JSON.stringify(opinewJson);\ndocument.querySelector('body').appendChild(el);\n&lt;\/script><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Case 2: You already have a JSON ld snippet included in your Shopify theme.<\/h2>\n\n\n\n<p>You can add this ID snippet code to make our reviews data work with your existing JSON ld<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">{% if product.metafields.opinew_metafields.reviews_count and product.metafields.opinew_metafields.reviews_count != \"0\" %} \n    \"aggregateRating\": {\n    \"@type\": \"AggregateRating\",\n    \"ratingValue\": {{ product.metafields.opinew_metafields.reviews_average }},\n    \"ratingCount\": {{ product.metafields.opinew_metafields.reviews_count }}\n},\n{% endif %}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Case 3: You&#8217;re using a JSON ld app<\/h2>\n\n\n\n<p>So far those are the Shopify apps that support Opinew:<\/p>\n\n\n\n<ul><li><a href=\"https:\/\/apps.shopify.com\/json-ld-for-seo\" class=\"rank-math-link\">JSON\u2011LD for SEO<\/a>\u00a0by\u00a0Little Stream Software. Check out our <a href=\"https:\/\/www.opinew.com\/help-center\/knowledge-base\/how-to-add-review-rich-snippets-with-json-ld-for-seo-and-opinew\/\" class=\"rank-math-link\">help center article<\/a> to integrate both apps<\/li><li><a href=\"https:\/\/www.opinew.com\/help-center\/knowledge-base\/search-results-rich-snippets-with-seo-all-in-one-and-opinew\/\" class=\"rank-math-link\">SEO All-In-One<\/a><\/li><li><a href=\"https:\/\/www.opinew.com\/help-center\/knowledge-base\/yoast-seo-and-opinew\/\" class=\"rank-math-link\">Yoast SEO<\/a><\/li><li><a href=\"https:\/\/www.opinew.com\/help-center\/knowledge-base\/opinew-and-seo-booster-shopify-integration\/\" class=\"rank-math-link\">SEO Booster<\/a><\/li><\/ul>\n\n\n\n<p>If your app doesn&#8217;t support Opinew yet, please get in touch with their support. Integrating with Opinew is very easy and should be quick for them to implement!<\/p>\n\n\n    \t\t<div class=\"hts-messages hts-messages--info  hts-messages--withtitle hts-messages--withicon \"   >\r\n    \t\t\t<span class=\"hts-messages__title\">We can help with installation<\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\tContact support via live chat in the bottom right corner of Opinew Dashboard and we will help you install the JSON ld codes.     \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n\n\n\n<h2 class=\"wp-block-heading\">Own a Shopify SEO app and want to integrate?<\/h2>\n\n\n\n<p>If you own a Shopify SEO app and would like to integrate with Opinew, please refer to our <a href=\"https:\/\/docs.google.com\/document\/d\/1XbmGS-GAgeOxPlURRe4Ggcv7xAT4hvWEissIZwcdkvk\" class=\"rank-math-link\">integration instructions<\/a>.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Case 1: No JSON ld included in your theme. We have prepared an easy-to-use default JSON ld snippet for you. Paste the ID snippet into your product.liquid Shopify template. You can ask us for help via live chat in the bottom right corner of the Opinew Dashboard if required. Case&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":[],"ht-kb-category":[17],"ht-kb-tag":[26],"_links":{"self":[{"href":"https:\/\/www.opinew.com\/help-center\/wp-json\/wp\/v2\/ht-kb\/449"}],"collection":[{"href":"https:\/\/www.opinew.com\/help-center\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.opinew.com\/help-center\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.opinew.com\/help-center\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.opinew.com\/help-center\/wp-json\/wp\/v2\/comments?post=449"}],"version-history":[{"count":18,"href":"https:\/\/www.opinew.com\/help-center\/wp-json\/wp\/v2\/ht-kb\/449\/revisions"}],"predecessor-version":[{"id":2585,"href":"https:\/\/www.opinew.com\/help-center\/wp-json\/wp\/v2\/ht-kb\/449\/revisions\/2585"}],"wp:attachment":[{"href":"https:\/\/www.opinew.com\/help-center\/wp-json\/wp\/v2\/media?parent=449"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.opinew.com\/help-center\/wp-json\/wp\/v2\/ht-kb-category?post=449"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.opinew.com\/help-center\/wp-json\/wp\/v2\/ht-kb-tag?post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}