Skip to content

Instantly share code, notes, and snippets.

@resistorsoftware
Created May 30, 2012 15:02
Show Gist options
  • Save resistorsoftware/2836867 to your computer and use it in GitHub Desktop.
Save resistorsoftware/2836867 to your computer and use it in GitHub Desktop.
SEO Manager Liquid
{% comment %} SEO Meta Manager - v1.0 {% endcomment %}
{% assign maxmeta = 155 %}
{% assign metaControl = false %}
{% if template contains 'product' %}
{% assign metaControl = true %}
{% assign metaArray = product.metafields.SEOMetaManager %}
{% assign defaultTitle = product.title %}
{% assign defaultDescription = product.description %}
{% elsif template contains 'page' %}
{% assign metaControl = true %}
{% assign metaArray = page.metafields.SEOMetaManager %}
{% assign defaultTitle = page.title %}
{% assign defaultDescription = page.content %}
{% elsif template contains 'collection' %}
{% assign metaControl = true %}
{% assign metaArray = collection.metafields.SEOMetaManager %}
{% assign defaultTitle = collection.title %}
{% assign defaultDescription = collection.description %}
{% elsif template contains 'blog' %}
<title>{{ page_title | escape }}</title>
<meta name='description' content='{{ shop.name }} - {{ page_title | escape }} blog' />
{% elsif template contains 'article' %}
<title>{{ page_title | escape }}</title>
<meta name='description' content=' {{ article.excerpt_or_content | strip_html | strip_newlines | escape | truncate: maxmeta }}' />
{% elsif template contains 'index' %}
<title>{{ shop.name }} - Welcome</title>
{% if shop.description != '' %}
<meta name='description' content='{{shop.description | escape }}' />
{% endif %}
{% elsif template contains '404' %}
<title>{{ shop.name }} - Page Not Found</title>
{% if shop.description != '' %}
<meta name='description' content='{{shop.description | escape }}' />
{% endif %}
{% endif %}
{% if metaControl == true %}
{% if metaArray == empty || metaArray == nil %}
{% if page_title != '' %}
<title>{{ page_title | escape }}</title>
{% else %}
<title>{{defaultTitle}}</title>
{% endif %}
<meta name='description' content='{{defaultDescription | strip_html | strip_newlines | truncate: maxmeta | escape}}' />
{% else %}
{% for keyVal in metaArray %}
{% capture key%}{{keyVal | first}}{%endcapture%}
{% capture value %}{{keyVal | last}}{% endcapture %}
{% case key %}
{% when 'title' %}
<title>{{value}}</title>
{% when 'description' %}
<meta name='description' content='{{value}}' />
{% when 'keywords' %}
<meta name='keywords' content='{{value}}' />
{% endcase %}
{% endfor %}
{% endif %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment