Solved

How To Define Title And Description For Particular Tags?

RaghavDev22
Tourist
9 0 1

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.

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

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

Accepted Solution (1)
David_Weru
Shopify Partner
177 16 43

This is an accepted solution.

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 -%}

 

 

View solution in original post

Replies 6 (6)

David_Weru
Shopify Partner
177 16 43

Hello RaghavDev22!

 

Your capture tag needs an endcapture tag.

 

Anything between the tags is added to the variable.

{% capture my_variable %}I am being captured.{% endcapture %}

{{ my_variable }} 

 

 

If you'd like further assistance, please message me.

LitExtension
Shopify Partner
4860 1001 1135

Hi @RaghavDev22

I checked and there is a lot of information displayed. Refer https://i.imgur.com/wZ0Gelq.png

Hope it clear to you.

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
RaghavDev22
Tourist
9 0 1

Yes, @LitExtension and @David_Weru I know that but It is also showing the other things in the title also. So, I want to show only my enter title for the particular tag. So, can you please suggest the code or solution.

David_Weru
Shopify Partner
177 16 43

This is an accepted solution.

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 -%}

 

 

RaghavDev22
Tourist
9 0 1

@David_Weru , Thank you for the answer.

David_Weru
Shopify Partner
177 16 43

You're welcome @RaghavDev22 

If you mark the post as a solution, it will be easier for others to find it.