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 -->
Hi,
I'm glad to participate in this topic.
It's best to place structured product data in the product template, as many Shopify themes on different websites are not the same, and the product template names vary. It's really difficult to answer with a universal location.
If you're looking to make your website's appearance in Google search more attractive, these search appearances need to be implemented with code. Common search appearances for Shopify stores include things like screenshots:
You can use the SEOAnt-AI SEO app to achieve this. Its advantage is that the code is in line with Google’s standards, so you don’t need to hire an expert; it can be done with one click. It’s also cost-effective, as most technical SEO functions are automated.
For all users who want to try solving structured data issues or those who want to optimize their website's SEO with an SEO tool, I’m offering a 40% off code “SEOAnt-AI SEO40%OFF”, valid for 2 months.Please be sure to install it through this link.
I wish you all a prosperous business!
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024