-
-
Save resistorsoftware/1216871 to your computer and use it in GitHub Desktop.
{% comment %} | |
- add this snippet to any product.liquid template, at the top of the file, and you can access the extra data provided by | |
the new version of Meta Tagger that supports Google Shopping. | |
{% endcomment %} | |
{% if template contains 'product' %} | |
{% if product.metafields.global %} | |
{% for mf in product.metafields.global %} | |
{% case mf.first %} | |
{% when 'MPN' %} | |
{% assign MPN = mf.last %} | |
{% when 'UPC' %} | |
{% assign UPC = mf.last %} | |
{% when 'JAN' %} | |
{% assign JAN = mf.last %} | |
{% when 'EAN' %} | |
{% assign EAN = mf.last %} | |
{% when 'ISBN' %} | |
{% assign ISBN = mf.last %} | |
{% endcase %} | |
{% endfor %} | |
{% endif %} | |
{% if product.metafields.google %} | |
{% for mf in product.metafields.google %} | |
{% case mf.first %} | |
{% when 'age_group' %} | |
{% assign age_group = mf.last %} | |
{% when 'gender' %} | |
{% assign gender = mf.last %} | |
{% when 'google_product_type' %} | |
{% assign google_product_type = mf.last %} | |
{% endcase %} | |
{% endfor %} | |
{% endif %} | |
{% endif %} | |
{% comment %} | |
- now you can use any of these tags... simple Liquid... | |
eg: | |
<span itemprop="identifier" content="mpn:{{MPN}}">MPN</span> | |
<span itemprop="identifier" content="upc:{{UPC}}">UPC</span> | |
<span itemprop="identifier" content="ISBN:{{ISBN}}">ISBN</span> | |
{% endcomment %} |
<link rel="canonical" href="{{ canonical_url | split: "?" | first}}" /> | |
{%- 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> | |
{%- 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> | |
{%- 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}} | Page {{current_page }}</title> | |
{%- 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>{{ shop.name }} - Welcome</title> | |
{%- if shop.description != '' -%} | |
<meta name="description" content="{{shop.description | 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> | |
{%- 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 }} {{ shop.name }}</title> | |
<meta name="description" content="{{ shop.name }} {{ blog.title | escape }} blog" /> | |
{%- endunless -%} | |
{%- elsif template contains 'article' -%} | |
{%- assign mf = article.metafields.meta_data -%} | |
{%- unless mf == empty -%} | |
{%- for mf in article.metafields.meta_data -%} | |
{%- capture key -%}{{ mf | first }}{%- endcapture -%} | |
{%- if key == 'title' -%} | |
<title>{{mf | last}}</title> | |
{%- 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=" {{ article.excerpt_or_content | strip_html | strip_newlines | escape | truncate: maxmeta }}" /> | |
{%- endunless -%} | |
{%- 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 -%} |
{% 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 %} |
<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 %} | |
{% capture productdesc %}{% include 'process-html-strip' with product.description %}{% endcapture %} | |
<title>{{ product.title }}{% if product.vendor != '' and settings.prod_show_vendor_meta %} by {{ product.vendor }}{% endif %} | {{ shop.name }}</title> | |
<meta name="description" content="{{ productdesc | strip_html | strip_newlines | truncatewords: maxwords | 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 }} | {{ shop.name }}</title> | |
<meta name="description" content="{{ page.content | strip_html | strip_newlines | truncatewords: maxwords | 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' %} | |
{% if settings.seo_tagline != '' %} | |
<title>{{ settings.seo_tagline }} - {{ shop.name }}</title> | |
{% else %} | |
<title>{{ shop.name }}</title> | |
{% endif %} | |
{% if settings.shop_description != '' %} | |
<meta name="description" content="{{ settings.shop_description | 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 }} {{ shop.name }}</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 }} - Welcome {% if template == "404" %} ==> Page Not Found <== {% endif %}</title> | |
{% if shop.description != '' %} | |
<meta name="description" content="{{shop.description | escape }}" /> | |
{% endif %} | |
{% endif %} |
resistorsoftware
commented
Apr 10, 2012
via email
No worries. Out of interest - why the limiting number of characters on title and description?
Dave ~ you have: {% if page_title != '' %} but page_title is never empty. It's annoying that you can't tell (I don't think) whether the page_title has been specifically set or is just e.g. product.title but the if-else you have now is irrelevant (I believe)...
True enough.. page_title represents whatever is set, either the special SEO title of the resource, or the ordinary title of the resource, and that is set by the server, so it seems that is correct, it is never empty... changed the code to reflect that... will have to check it out... thanks
Hi Dave,
I installed the Meta-Tagger App on our theme in Shopify and it is not showing in the admin dashboard.
Can you help me with this? Thanks
Dave,
Im in the same boat as aforonda. im not sure how to get started. when i click get started in the app it just brings me to the dashboard... then i discovered your email.. i went through the installation procedure and the app still doesnt come up. what do i do?