Skip to content

Instantly share code, notes, and snippets.

@haroldao
Last active December 19, 2020 00:34
Show Gist options
  • Save haroldao/59557ebfba329e41401f1b1275f54b4f to your computer and use it in GitHub Desktop.
Save haroldao/59557ebfba329e41401f1b1275f54b4f to your computer and use it in GitHub Desktop.
<!-- /snippets/schema-markup.liquid -->
<script type="application/ld+json">
{%- if template == 'index' -%}
{
"@context": "http://schema.org",
"@type": "WebSite",
"name": "{{ shop.name }}",
"alternateName": "{{ shop.description }}",
"url": "{{ shop.url }}"
}
{%- elsif template == 'product' %}
{
"@context": "http://schema.org",
"@type": "Product",
"description": "{{ product.description | strip_html }}",
"name": "{{ product.title }}",
"productID": "{{product.id}}",
"image": "{{ product.featured_image | img_url: 'master' }}",
"manufacturer": "{{ product.vendor }}",
"category": "{{ collection.title }}",
"url": "{{ shop.url | append: product.url }}",
{% if product.first_available_variant.sku != blank %}
"sku": "{{ product.first_available_variant.sku }}",
{% else %}
"sku": "{{ product.first_available_variant.id }}",
{% endif %}
{% if product.first_available_variant.barcode.size == 12 %}
"gtin12": {{ product.first_available_variant.barcode }},
{% endif %}
{% if product.first_available_variant.barcode.size == 13 %}
"gtin13": {{ product.first_available_variant.barcode }},
{% endif %}
{% if product.first_available_variant.barcode.size == 14 %}
"gtin14": {{ product.first_available_variant.barcode }},
{% endif %}
"brand": {
"@type": "Thing",
"name": "{{product.vendor | escape}}"
},
"offers": {
"@type": "Offer",
"availability": "{% if product.available %}InStock{% else %}OutOfStock{% endif %}",
"url":"{{shop.url}}{{product.url}}"
"price": "{{ product.price | money_without_currency }}",
"priceCurrency": "{{ shop.currency }}"
}
}
{%- elsif template == 'article' %}
{
"@context": "http://schema.org",
"@type": "NewsArticle",
"image": {
"@type": "imageObject",
"url": "https:{{ article.image.src | img_url: 'original' }}",
"width": "1024px",
"height": "1024px"
},
"keywords": "{%- for tag in article.tags -%}{{ tag }}{%- unless forloop.last -%}, {%- endunless -%}{%- endfor -%}",
"url": "{{ shop.url | append: article.url }}",
"description": "{{ article.content | truncatewords: 100 | strip_html }}",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://google.com/article"
},
"headline": "{{ article.title }}",
"datePublished": "{{ article.published_at }}",
"dateModified": "{{ article.published_at }}",
"author": {
"@type": "Person",
"name": "{{ article.author }}"
},
"publisher": {
"@type": "Organization",
"name": "{{ shop.name }}",
"logo": {
"@type": "ImageObject",
"url": "{{ shop.url }}"
}
},
"commentCount": "{{ article.comments_count }}"
}
{%- endif %}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment