Skip to content

Instantly share code, notes, and snippets.

@resistorsoftware
Created May 9, 2012 03:45
Show Gist options
  • Save resistorsoftware/2641643 to your computer and use it in GitHub Desktop.
Save resistorsoftware/2641643 to your computer and use it in GitHub Desktop.
Meta Tagger Liquid with some comments
{% comment %} this is useful as Shopify ensures canonical just works {% endcomment %}
<link rel="canonical" href="{{ canonical_url }}" />
{% comment %} this is simple a limit for when we blindly dump Shopify data for SEO, the old hail mary pass {% endcomment %}
{% assign maxmeta = 155 %}
{% comment %} PRODUCT SEO!!! {% endcomment %}
{% if template contains 'product' %}
{% comment %} Okay, does this Product have any meta_data from the App {% endcomment %}
{% assign mf = product.metafields.meta_data %}
{% unless mf == empty %}
{% comment %} Meta Tagger was used for this Product {% endcomment %}
{% for mf in product.metafields.meta_data %}
{% capture key %}{{ mf | first }}{% endcapture %}
{% comment %} Looking for the title {% endcomment %}
{% if key == 'title' %}
<title>{{mf | last}}</title>
<meta name="title" content="{{mf | last}}" />
{% endif %}
{% comment %} Looking for the description {% endcomment %}
{% if key == 'meta_description' %}
<meta name="description" content="{{mf | last}}" />
{% endif %}
{% comment %} Looking for the keywords {% endcomment %}
{% if key == 'keywords' %}
<meta name="keywords" content="{{mf | last}}" />
{% endif %}
{% endfor %}
{% else %}
{% comment %} Meta Tagger was NOT used, dump out some Hail Mary defaults!! {% endcomment %}
<title>{% if page_title != '' %}{{ page_title | escape }}{% else %}{{product.title}}{% endif %}</title>
<meta name="description" content="{{product.description | strip_html | strip_newlines | truncate: maxmeta | escape}}" />
{% endunless %}
{% comment %} PAGE SEO!!! {% endcomment %}
{% elsif template contains 'page' %}
{% comment %} Does this Page have any meta_data from the App {% endcomment %}
{% assign mf = page.metafields.meta_data %}
{% unless mf == empty %}
{% comment %} Meta Tagger was used for this Page {% endcomment %}
{% for mf in page.metafields.meta_data %}
{% capture key%}{{ mf | first }}{%endcapture%}
{% comment %} Looking for the title {% endcomment %}
{% if key == 'title' %}
<title>{{mf | last}}</title>
<meta name="title" content="{{mf | last}}" />
{% endif %}
{% comment %} Looking for the description {% endcomment %}
{% if key == 'meta_description' %}
<meta name="description" content="{{mf | last}}" />
{% endif %}
{% comment %} Looking for the keywords {% endcomment %}
{% if key == 'keywords' %}
<meta name="keywords" content="{{mf | last}}" />
{% endif %}
{% endfor %}
{% else %}
{% comment %} Meta Tagger was NOT used, dump out some Hail Mary defaults for the Page! {% endcomment %}
<title>{% if page_title != '' %}{{ page_title | escape }}{% else %}{{page.title}}{% endif %}</title>
<meta name="description" content="{{page.content | strip_html | strip_newlines | truncate: maxmeta | escape}}" />
{% endunless %}
{% comment %} COLLECTION SEO!!! {% endcomment %}
{% elsif template contains 'collection' %}
{% comment %} Does this Collection have any meta_data from the App {% endcomment %}
{% assign mf = collection.metafields.meta_data %}
{% unless mf == empty or mf == nil %}
{% comment %} Meta Tagger was used for this Collection {% endcomment %}
{% for mf in collection.metafields.meta_data %}
{% capture key%}{{ mf | first }}{%endcapture%}
{% comment %} Looking for the title {% endcomment %}
{% if key == 'title' %}
<title>{{mf | last}}</title>
<meta name="title" content="{{mf | last}}" />
{% endif %}
{% comment %} Looking for the description {% endcomment %}
{% if key == 'meta_description' %}
<meta name="description" content="{{mf | last}}" />
{% endif %}
{% comment %} Looking for the keywords {% endcomment %}
{% if key == 'keywords' %}
<meta name="keywords" content="{{mf | last}}" />
{% endif %}
{% endfor %}
{% else %}
{% comment %} Meta Tagger was NOT used, dump out some Hail Mary defaults for the Collection! {% endcomment %}
<title>{{ shop.name }} - {% if page_title != '' %}{{ page_title | escape }}{% else %}{{collection.title}}{% endif %}</title>
<meta name="description" content="{{collection.description | strip_html | strip_newlines | truncate: maxmeta | escape}}" />
{% endunless %}
{% comment %}
Your Shop HOMEPAGE SEO!!! This is probably what you are interested in... too
{% endcomment %}
{% elsif template contains 'index' %}
{% comment %}
The *** TITLE ***
- Yes, this default is totally boring. Usually you can merge something clever from your Shop's Theme into here
- Some themes use a setting in the SEO, like settings.title. Others make up some dumb connection with pages.
- Just paste in whatever you want.. it is not like you change this everyday...
{% endcomment %}
<title>{{ shop.name }} - Welcome</title>
{% comment %} This comes from your Shop Preferences. Use this wisely and well. {% endcomment %}
{% if shop.description != '' %}
<meta name="description" content="{{shop.description | escape }}" />
{% endif %}
{% comment %} If you have a Blog, this is the SEO that gets rendered. Customize as you wish {% 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 %} If you have a Blog Article, this is the SEO that gets rendered. Customize as you wish {% 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 }}" />
{% comment %}
The end of the line. This is the default stuff nothing else triggers. copy of your homepage SEO here maybe?
{% endcomment %}
{% else %}
<title>{{ shop.name }} - Welcome {% if template == "404" %} ==> Page Not Found <== {% endif %}</title>
{% if shop.description != '' %}
<meta name="description" content="{{shop.description | escape }}" />
{% endif %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment