Skip to content

Instantly share code, notes, and snippets.

@MatthewKennedy
Forked from resistorsoftware/Google Shopping Snippet
Created February 24, 2012 02:09
Show Gist options
  • Save MatthewKennedy/1896700 to your computer and use it in GitHub Desktop.
Save MatthewKennedy/1896700 to your computer and use it in GitHub Desktop.
Enhanced Meta Tagger Snippet With Blog and Article
{% assign maxmeta = 155 %}
<link rel="canonical" href="{{ canonical_url }}" />
{% if template contains 'product' %}
{% 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 %}
{% else %}
<title>{% if page_title != '' %}{{ page_title | escape }}{% else %}{{product.title}} - {{ shop.name }}{% endif %}</title>
<meta name="description" content="{{ product.description | strip_html | strip_newlines | truncatewords: maxmeta | escape }}" />
{% 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 %}
{% else %}
<title>{% if page_title != '' %}{{ page_title | escape }}{% else %}{{page.title}}{% endif %}</title>
<meta name="description" content="{{ page.content | strip_html | strip_newlines | truncatewords: maxmeta | escape }}" />
{% endunless %}
{% elsif template contains 'collection' %}
{% assign mf = collection.metafields.meta_data %}
{% unless mf == empty %}
{% for mf in collection.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 %}
{% else %}
<title>{% if page_title != '' %}{{ page_title | escape }}{% else %}{{collection.title}}{% endif %}</title>
<meta name="description" content="{{ collection.description | strip_html | strip_newlines | truncatewords: maxmeta | escape }}" />
{% endunless %}
{% elsif template contains 'index' %}
<title>Welcome to {{ shop.name }}</title>
{% if shop.description != '' %}
<meta name="description" content="{{shop.description}}" />
{% endif %}
{% comment %}Blog {% endcomment %}
{% elsif template contains 'blog' %}
<title>{% if page_title != '' %}{{ page_title | escape }}{% else %} {{ blog.title }} {{ shop.name }}!'{% endif %}</title>
<meta name="description" content="{{ shop.name }} {{ blog.title | escape }} blog" />
{% comment %}Articles {% endcomment %}
{% elsif template contains 'article' %}
<title>{% if page_title != '' %}{{ page_title | escape }}{% else %}{{ shop.name }} - {{ article.title }}{% endif %}</title>
<meta name="description" content=" {{ article.excerpt_or_content | strip_html | strip_newlines | escape | truncate: maxmeta }}" />
{% else %}
<title>{% if page_title != '' %}{{ page_title | escape }} {{ shop.name }}{% else %} Welcome to {{ shop.name }} {% endif %}{% if template == "404" %} ==> Page Not Found <== {% endif %}</title>
{% if shop.description != '' %}
<meta name="description" content="{{shop.description}}" />
{% endif %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment