I've been working on this for a while and havent been able to come up with a solution. We have a shopify store with various markets (each under their own tdl). For SEO, we want the ability to have a country specific page title tag for each collection. I've created metafields for the collections, and populated with a page title we want to include.
collection.metafields.pgtitle.aus
collection.metafields.pgtitle.usa
collection.metafields.pgtitle.nzl
collection.metafields.pgtitle.global
I've created a snippet to include when page type = collection:
{% if localization.country.iso_code == 'AU' and collection.metafields.pgtitle.aus != "" %}
<title>{{ collection.metafields.pgtitle.aus }}</title>
{% elsif localization.country.iso_code == 'NZ' and collection.metafields.pgtitle.nzl != "" %}
<title>{{ collection.metafields.pgtitle.nzl | metafield_text }}</title>
{% elsif localization.country.iso_code == 'US' and collection.metafields.pgtitle.usa != "" %}
<title>{{ collection.metafields.pgtitle.usa }}</title>
{% elsif collection.metafields.pgtitle.global != "" %}
<title>{{ collection.metafields.pgtitle.global }}</title>
{% else %}
{%- capture seo_title -%}
{%- if request.page_type == 'search' and search.performed == true -%}
{{ 'general.search.heading' | t: count: search.results_count }}: {{ 'general.search.results_with_count' | t: terms: search.terms, count: search.results_count }}
{%- else -%}
{{ page_title }}
{%- endif -%}
{%- if current_tags -%}
{%- assign meta_tags = current_tags | join: ', ' -%} – {{ 'general.meta.tags' | t: tags: meta_tags -}}
{%- endif -%}
{%- if current_page != 1 -%}
– {{ 'general.meta.page' | t: page: current_page }}
{%- endif -%}
{%- assign escaped_page_title = page_title | escape -%}
{%- unless escaped_page_title contains shop.name -%}
– {{ shop.name }}
{%- endunless -%}
{%- endcapture -%}
<title>{{ seo_title }}</title>
{% endif %}
The logic sees to work well, I can see the tags showing where expected, issue is the metafield is not showing, so the result when the condition is met is:
<title></title>
I'm placing this in the theme.liquid file.
How can I get these metafields to show?
Thanks in advance!