user4889134
user4889134

Reputation: 111

Shopify - remove store title from products page <title> tag

I am working on a shopify store and I cannot seem to get the code right for removing the store name from only the product pages.

Here is the code:

<title>
  {{ page_title }}
  {% 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 %}
  {% unless page_title contains shop.name %}
  {% if template != 'article' %} &ndash; {{ shop.name }}{% endif %}{% endunless %}
</title>

I have tried using an if statement above this to change page_title to product_title but it breaks this code and no titles show up on any other pages.

Also this code prevents the store name from coming up on articles. I tried using the same code but replaced it with 'product' and it did not work!

All help is appreciated. Thanks!

Upvotes: 0

Views: 1354

Answers (2)

user4889134
user4889134

Reputation: 111

Found the solution ... an if/else statement. I thought I had tried this without success but it is working now.

{% if template == 'product' %} 
<title>{{ page_title }}</title> 
{% else %} 
<title>{{ page_title }}{% 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 %}{% unless page_title contains shop.name %}{% if template != 'article' %} &ndash; {{ shop.name }}{% endif %}{% endunless %}</title> 
{% endif %} 

Upvotes: 0

Mennyg
Mennyg

Reputation: 330

Try this: before and after your shop name add an unless, like this:

{% unless template contains 'product' %}
{% unless template contains 'article' %}
 – {{ shop.name }}
{% endunless %}
{% endunless %}

Also, you should think about using different lines in your code, makes things more readable. Also, using contains instead of = is more foolproof, so I took the liberty of changing that for you

Upvotes: 1

Related Questions