All things Shopify and commerce
Hi there!
I would like to add the code from Google structured data markup about product and home page to shopify store . But I don't know where should I add it .
Pls help me and tell me what file should I paste it .
Thanks !
Solved! Go to the solution
This is an accepted solution.
Hi there,
Adding structured data to your theme will go into different places depending on what exactly you're adding.
For products, you'll add it to your product template. If you want it on every page, you'd do it in the theme's layout template.
Make sure you test your pages to ensure the structured data is done properly. You can use this article to evaluate the code https://www.ilanadavis.com/articles/test-json-ld-code-shopify
This is an accepted solution.
Hi there,
Adding structured data to your theme will go into different places depending on what exactly you're adding.
For products, you'll add it to your product template. If you want it on every page, you'd do it in the theme's layout template.
Make sure you test your pages to ensure the structured data is done properly. You can use this article to evaluate the code https://www.ilanadavis.com/articles/test-json-ld-code-shopify
You can add the below code anywhere to your product.liquid page, assuming no other structured data is added. If you have other coding, best to remove this.
<!-- Copyright FeedArmy 2023 Version 3.20 -->
<!-- CODE SETTINGS START -->
<!-- CODE SETTINGS START -->
<!-- Please add your alpha2 code, you can find it here: https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference/enum/countrycode -->
{%- assign fa_product_id_alpha2_code = 'US' -%}
<!-- set your product id values are default, product_id, parent_id, sku-->
{%- assign fa_product_id = 'default' -%}
<!-- CODE SETTINGS END -->
<!-- CODE SETTINGS END -->
<!-- ==================================== -->
<!-- DO NOT EDIT ANYTHING BELOW THIS LINE -->
{%- if template contains 'product' -%}
{%- assign fa_current_variant = product.selected_or_first_available_variant -%}
{%- if fa_product_id == 'default' -%}
{%- capture fa_product_id_value -%}shopify_{{ fa_product_id_alpha2_code }}_{{ product.id }}_{{ fa_current_variant.id }}{%- endcapture -%}
{%- elsif fa_product_id == 'product_id' -%}
{%- capture fa_product_id_value -%}{{ fa_current_variant.id }}{%- endcapture -%}
{%- elsif fa_product_id == 'parent_id' -%}
{%- capture fa_product_id_value -%}{{product.id }}{%- endcapture -%}
{%- elsif fa_product_id == 'sku' -%}
{%- capture fa_product_id_value -%}{{ fa_current_variant.sku | escape }}{%- endcapture -%}
{%- endif -%}
{%- if cart.currency.iso_code == 'GBP' or cart.currency.iso_code == 'USD' or cart.currency.iso_code == 'JPY' or cart.currency.iso_code == 'AUD' or cart.currency.iso_code == 'AED' or cart.currency.iso_code == 'CAD' or cart.currency.iso_code == 'BWP' or cart.currency.iso_code == 'BND' or cart.currency.iso_code == 'DOP' or cart.currency.iso_code == 'GTQ' or cart.currency.iso_code == 'HKD' or cart.currency.iso_code == 'INR' or cart.currency.iso_code == 'ILS' or cart.currency.iso_code == 'YEN' or cart.currency.iso_code == 'KES' or cart.currency.iso_code == 'KOR' or cart.currency.iso_code == 'LBP' or cart.currency.iso_code == 'MYR' or cart.currency.iso_code == 'MXN' or cart.currency.iso_code == 'NPR' or cart.currency.iso_code == 'NZD' or cart.currency.iso_code == 'NIO' or cart.currency.iso_code == 'NGN' or cart.currency.iso_code == 'PKR' or cart.currency.iso_code == 'CNY' or cart.currency.iso_code == 'PHP' or cart.currency.iso_code == 'SGD' or cart.currency.iso_code == 'LKR' or cart.currency.iso_code == 'CHF' or cart.currency.iso_code == 'TWD' or cart.currency.iso_code == 'TSH' or cart.currency.iso_code == 'THB' or cart.currency.iso_code == 'UGX' or cart.currency.iso_code == 'KWD' or cart.currency.iso_code == 'CLP' or cart.currency.iso_code == 'BHD' -%}
{%- assign fa_product_price = fa_current_variant.price | money_without_currency | remove:',' -%}
{%- else -%}
{%- assign fa_product_price = fa_current_variant.price | money_without_currency | remove:'.' | replace: ',', '.' -%}
{%- endif -%}
<script type="application/ld+json" data-creator_name="FeedArmy">
{
"@context": "http://schema.org/",
"@type": "Product",
"@id": {{ canonical_url | json }},
"name": "{{ product.title | strip_html | escape }}",
"url": "{{ shop.url }}{{ product.url }}",
"sku": "{{fa_product_id_value}}",
{%- if product.variants.first.barcode.size >= 12 and product.variants.first.barcode.size <= 14 -%}
"gtin": {{ product.variants.first.barcode }},
{%- endif -%}
"productID": "{{ product.id }}",
"brand": {
"@type": "Brand",
"name": "{{ product.vendor | escape }}"
},
"description": {{ product.description | strip_html | json }},
"image": "https:{{ product.featured_image.src | img_url: '1500x1500' }}",
{%- if product.variants -%}
"offers":
{
"@type" : "Offer",
"priceCurrency": "{{ cart.currency.iso_code }}",
"price": "{{ fa_product_price }}",
"itemCondition" : "http://schema.org/NewCondition",
"availability" : "http://schema.org/{% if fa_current_variant.available %}InStock{% else %}OutOfStock{% endif %}",
"url" : "{{ shop.url }}{{ fa_current_variant.url }}",
{%- if fa_current_variant.image -%}
{%- assign variant_image_size = fa_current_variant.image.width | append: 'x' -%}
"image": "https:{{ fa_current_variant.image.src | img_url: variant_image_size }}",
{%- else -%}
"image": "https:{{ product.featured_image.src | img_url: '1500x1500' }}",
{%- endif -%}
{%- if fa_current_variant.title != 'Default Title' -%}
"name" : "{{ product.title | strip_html | escape }} - {{ fa_current_variant.title | escape }}",
{%- else -%}
"name" : "{{ product.title | strip_html | escape }}",
{%- endif -%}
{%- if fa_current_variant.barcode.size >= 12 and fa_current_variant.barcode.size <= 14 -%}
"gtin": {{ product.variants.first.barcode }},
{%- endif -%}
"sku": "{{fa_product_id_value}}",
{%- if product.description != blank -%}
"description" : {{ product.description | strip_html | json }},
{%- endif -%}
"priceValidUntil": "{{ 'now' | date: '%s' | plus: 31536000 | date: '%Y-%m-%d' | uri_encode | replace:'+','%20' }}"
}
{%- if product.variants.size > 1 -%},
"additionalProperty": [{
"@type": "PropertyValue",
"propertyID": "item_group_id",
"value": "{{ product.id }}"
}]
{%- endif -%}
{%- if product.metafields.spr.reviews -%}
{%- assign fa_rating = product.metafields.spr.reviews | split: '"reviewCount": "' | last | split: '"' | first | plus: 0 -%}
{%- if fa_rating > 0 -%}
,"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": {{ product.metafields.spr.reviews | split: '"ratingValue": "' | last | split: '"' | first | plus: 0 }},
"ratingCount": {{ product.metafields.spr.reviews | split: '"reviewCount": "' | last | split: '"' | first | plus: 0 }}
}
{%- endif -%}
{%- endif -%}
{%- endif -%}
}
</script>
{%- endif -%}
<!-- Copyright FeedArmy 2023 Version 3.20 -->
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024