Skip to content

Instantly share code, notes, and snippets.

@JamieS
Forked from resistorsoftware/Google Shopping Snippet
Created October 18, 2011 15:04
Show Gist options
  • Save JamieS/1295657 to your computer and use it in GitHub Desktop.
Save JamieS/1295657 to your computer and use it in GitHub Desktop.
Enhanced Meta-Titler snippet
{% assign maxwords = 30 %}
{% if template == 'product' %}
{% if collection %}
<link rel="canonical" href="{{ shop.url }}{{ product.url }}" />
{% endif %}
{% assign mf = product.metafields.meta_data %}
{% unless mf == empty %}
{% for mf in product.metafields.meta_data' %}
{% capture key %}{{ mf | first }}{% endcapture %}
{% if key == 'title' %}
<title>{{mf | last}}</title>
<meta name="title" content="{{mf | last}}" />
{% endif %}
{% if key == 'meta_description' %}
<meta name="description" content="{{mf | last}}" />
{% endif %}
{% if key == 'keywords' %}
<meta name="keywords" content="{{mf | last}}" />
{% endif %}
{% endfor %}
{% endunless %}
{% elsif template contains 'page' %}
{% assign mf = page.metafields.meta_data %}
{% unless mf == empty %}
{% for mf in page.metafields.meta_data' %}
{% capture key%}{{ mf | first }}{%endcapture%}
{% if key == 'title' %}
<title>{{mf | last}}</title>
<meta name="title" content="{{mf | last}}" />
{% endif %}
{% if key == 'meta_description' %}
<meta name="description" content="{{mf | last}}" />
{% endif %}
{% if key == 'keywords' %}
<meta name="keywords" content="{{mf | last}}" />
{% endif %}
{% endfor %}
{% endunless %}
{% elsif template == 'collection' %}
<title>{{ shop.name }} - {{ page_title | escape }}</title>
<meta name="description" content="{{collection.description | strip_html | strip_newlines | truncatewords: maxwords | escape}}" />
{% elsif template == 'index' %}
<title>{{ shop.name }} - {{ page_title | escape }}</title>
<meta name="description" content="My store is very special, and this is the homepage!" />
{% else %}
<meta name="description" content="This is my generic description of my shop..." />
<title>{{ shop.name }} - {{ page_title | escape }}</title>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment