Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save resistorsoftware/2302037 to your computer and use it in GitHub Desktop.
Save resistorsoftware/2302037 to your computer and use it in GitHub Desktop.
Meta Tagger Snippet for Expo Theme
<link rel="canonical" href="{{ canonical_url }}" />
{% assign maxmeta = 155 %}
{% 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>{{ page_title | escape }}</title>
<meta name="description" content="{{product.description | strip_html | strip_newlines | truncate: 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>{{ page_title | escape }}</title>
<meta name="description" content="{{page.content | strip_html | strip_newlines | truncate: maxmeta | escape}}" />
{% endunless %}
{% elsif template contains 'collection' %}
{% assign mf = collection.metafields.meta_data %}
{% unless mf == empty or mf == nil %}
{% 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>{{ shop.name }} - {{ page_title | escape }}</title>
<meta name="description" content="{{collection.description | strip_html | strip_newlines | truncate: maxmeta | escape}}" />
{% endunless %}
{% elsif template contains 'index' %}
<title>{% if settings.title_tags != "" %}{{ settings.title_tags }}{% endif %} - {{ page_title | escape }}</title>
{% if settings.meta_description != '' %}
<meta name="description" content="{{settings.meta_description | escape }}" />
{% elsif shop.description != '' %}
<meta name="description" content="{{shop.description | escape }}" />
{% endif %}
{% if settings.meta_keywords != '' %}
<meta name="keywords" content="{{settings.meta_keywords | escape }}" />
{% endif %}
{% elsif template contains 'blog' %}
{% assign mf = blog.metafields.meta_data %}
{% unless mf == empty %}
{% for mf in blog.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>{{ page_title | escape }}</title>
<meta name="description" content="{{ shop.name }} {{ blog.title | escape }} blog" />
{%endunless %}
{% elsif template contains 'article' %}
<title>{{ page_title | escape }}</title>
<meta name="description" content=" {{ article.excerpt_or_content | strip_html | strip_newlines | escape | truncate: maxmeta }}" />
{% else %}
<title>{{ shop.name }} - {{ page_title | escape }}{% if settings.title_tags != "" %} - {{ settings.title_tags }}{% endif %}{% if template == "404" %} ==> Page Not Found <== {% endif %}</title>
{% if settings.meta_description != '' %}
<meta name="description" content="{{settings.meta_description | escape }}" />
{% elsif shop.description != '' %}
<meta name="description" content="{{shop.description | escape }}" />
{% endif %}
{% if settings.meta_keywords != '' %}
<meta name="keywords" content="{{settings.meta_keywords | escape }}" />
{% endif %}
{% endif %}
{% assign maxmeta = 155 %}
{% if template contains '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 %}
{% else %}
<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 %}
{% 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 | truncate: maxmeta | escape}}" />
{% endunless %}
{% elsif template contains 'collection' %}
{% assign mf = collection.metafields.meta_data %}
{% unless mf == empty or mf == nil %}
{% 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>{{ 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 %}
{% elsif template contains 'index' %}
<title>{{ shop.name }} - {{ page_title | escape }}{% if settings.title_tags != "" %} - {{ settings.title_tags }}{% endif %}</title>
{% if settings.meta_description != '' %}
<meta name="description" content="{{settings.meta_description | escape }}" />
{% elsif shop.description != '' %}
<meta name="description" content="{{shop.description | escape }}" />
{% endif %}
{% if settings.meta_keywords != '' %}
<meta name="keywords" content="{{settings.meta_keywords | escape }}" />
{% endif %}
{% 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" />
{% 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>{{ shop.name }} - {{ page_title | escape }}{% if settings.title_tags != "" %} - {{ settings.title_tags }}{% endif %}{% if template == "404" %} ==> Page Not Found <== {% endif %}</title>
{% if settings.meta_description != '' %}
<meta name="description" content="{{settings.meta_description | escape }}" />
{% elsif shop.description != '' %}
<meta name="description" content="{{shop.description | escape }}" />
{% endif %}
{% if settings.meta_keywords != '' %}
<meta name="keywords" content="{{settings.meta_keywords | escape }}" />
{% endif %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment