Menu Close

Get Support From ShopWired Close

All Systems Are Operational

Subscribe To Updates
Prefer To Live Chat? Chat directly with ShopWired support Available 9.00am to 7.00pm Monday to Friday
11.00am to 5.00pm Saturday
Quickest response time

Send A Message
Response within 24 hours

Menu Close

Menu

How to add structured data to the products on your theme

You can add code to your theme's files to provide Google, and other search engines/providers, with detailed information about your products (in a structured format), by following the instructions below.

More information about Structured Data can be found on Google's website here and on the schema.org/Product website here.


Adding the code

You'll need to use the page editor to make changes to the product.twig file for your theme.

Open the product.twig file.

Scroll to the bottom of the file. Right before the {% endblock %} piece of code, add the code shown below.

<script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "Product",
  "name": "{{ product.title|replace('"', "'") }}",
  "image": "https:{{ product.photo_url }}",
  "description": "{{ product.description|striptags|replace('"', "'") }}",
  {% if product.mpn %}
      "mpn": "{{ product.mpn|replace('"', "'") }}",
  {% endif %}
  {% if product.gtin %}
      "gtin": "{{ product.gtin|replace('"', "'") }}",
  {% endif %}
  {% if product.brand %}
      "brand": {
        "@type": "Thing",
        "name": "{{ product.brand.title|replace('"', "'") }}"
      },
  {% endif %}
  {% if product.sku %}
     "sku": {{ product.sku|json_encode|raw }},
  {% endif %}
  {% if reviews_enabled %}
        "aggregateRating": {
            "@type": "AggregateRating",
            "ratingValue": "{{ product.rating }}",
            "reviewCount": "{{ product.reviews|length }}"
        },
   {% endif %}
   {% if product.variations %}
	"offers": [
		{% for variation in product.variations %}
			{ 
			"@type": "Offer",
			"price": "{{ variation.price }}",
			"priceCurrency": "GBP",
			"priceValidUntil": "2020-11-05",
			"itemCondition": "http://schema.org/NewCondition",
			"url": "{{ product.url }}",
			{% if variation.sku %}
				"sku": "{{ variation.sku }}",
			{% endif %}
			{% if variation.gtin %}
				"gtin": "{{ variation.gtin }}",
			{% endif %}
			{% if variation.mpn %}
			    "mpn": "{{ variation.mpn|replace('"', "'") }}",
			{% endif %}
			{% if variation.in_stock %}
				"availability": "https://schema.org/InStock",
			{% else %}
				"availability": "https://schema.org/OutOfStock",
			{% endif %}
			"seller": {
			  "@type": "Organization",
			  "name": "{{ global.business.name }}" }
			}{% if loop.last %}{% else %},{% endif %}
		{% endfor %}
	]
  {% else %}
  "offers": {
    "@type": "Offer",
    "priceCurrency": "GBP",
       {% if product.sale_price > 0 %}
       "price": "{{ product.sale_price }}",
       {% else %}
       "price": "{{ product.price }}",
       {% endif %}
    "url": "{{ product.url }}",
    "priceValidUntil": "2020-11-05",
    "itemCondition": "http://schema.org/NewCondition",
    {% if product.in_stock %}
        "availability": "https://schema.org/InStock",
    {% endif %}
    "seller": {
      "@type": "Organization",
      "name": "{{ global.business.name }}"
    }
  }
  {% endif %}
}
</script>

As shown in the example below.

You can use Google's Structured Data Testing Tool to test that the code is working and has been added correctly.