Ad

How To Define Title And Description For Particular Tags In Shopify?

- 1 answer

I am adding the title and description for the particular tags in theme.liquid but it is not coming properly. Any help is much appreciated.

I want to show the "Himalayan Salt Lamp SEO Title" for the tag but other things are coming in the title like the collection title, so I want to show only my added title for the tag.

This is my code:

{%- 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 contains 'Himalayan Salt Lamp' %}
Himalayan Salt Lamp SEO Title
{% endif %}

{% unless collection.tags contains 'Himalayan Salt Lamp' %}
  {%- assign meta_tags = current_tags | join: ', ' -%} – {{ 'general.meta.tags' | t: tags: meta_tags -}}
{% endunless %}

{%- 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 | strip }} </title>

{%- if page_description -%}
<meta name="description" content="{{ page_description | escape }}">
{%- endif -%}

It is showing some title but it is also showing the collection title, so I don't want to show that.

Any help is much appreciated.

Ad

Answer

This code should give you just that 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 contains 'Himalayan Salt Lamp' %}


{%- capture seo_title -%}
Himalayan Salt Lamp SEO Title
{%- endcapture -%}


{% endif %}
{%- if current_tags -%}
{%- assign meta_tags = current_tags | join: ', ' -%} &ndash; {{ 'general.meta.tags' | t: tags: meta_tags -}}
{%- endif -%} 

{%- if current_page != 1 -%}
&ndash; {{ 'general.meta.page' | t: page: current_page }}
{%- endif -%}
{%- assign escaped_page_title = page_title | escape -%}
{%- unless escaped_page_title contains shop.name -%}
&ndash; {{ shop.name }}
{%- endunless -%}


<title>{{ seo_title | strip }} </title> 

{%- if page_description -%}
<meta name="description" content="{{ page_description | escape }}">
{%- endif -%}
Ad
source: stackoverflow.com
Ad