Dynamic titles for product pages and appropriate titles for all other pages

I don't know if I'm going about this the best way (hopefully I am), but I inserted the following code I found from a post on this website into my layout/theme.liquid file to make my product titles dynamic: <title>{% if template == "product" %}{{ product.title }} | {{ shop.name }}{% endif %}</title> Mission accomplished. It worked just as I'd hoped. However, now my products are the only pages with titles. How can I edit the code so all the pages (not just the products) have appropriate titles for SEO?

Comment (2)

Jese Leos

August 19, 2024

Verified user

All you need is an else condition: <title>{% if template == "product" %}{{ product.title }} | {{ shop.name }}{% else %}{{ page_title }}{% endif %}</title> HTH

Jese Leos

August 19, 2024

Verified user

Use the default liquid object to show the titles, you can check more about this here page_title Also, you can check the reference code from theme.liquid file of the default dawn theme from Shopify itself Dawn theme

You’ll be in good company