Displaying Tag on blog.liquid template for tagged archive pages

Hi. I am new to Shopify and have been tasked with building a new Blog section. I have managed to build a bespoke blog template (blog.myname.liquid) which displays correctly but when that template is used to show all the articles that have a specific tag (/blogs/blog-name/tagged/tag-name/) I want to display that tag name in the header instead of the blog title. It seems a very simple thing to do, but I can’t seem to find anything online that works. Please forgive me if I am using incorrect terminology.

Hey Michael,

So Shopify doesn’t provide a built-in Liquid variable for the active tag, so you’ll need to get the tag from the actual URL of the page. You can use the request.path Liquid object to get the URL and then use Liquid filters to isolate the tag name.

Depending on the theme you’re using, the blog title should be appearing in a .liquid file and look something like this:

<h1>
  {{ blog.title}}
</h1>

You can replace the above with this:

{%- assign tag_title = request.path | split: '/tagged/' | last | replace: '-', ' ' | capitalize -%}

<h1>
  {%- if request.path contains '/tagged/' -%}
    {{ tag_title }}
  {%- else -%}
    {{ blog.title | escape }}
  {%- endif -%}
</h1>

Now the title will be the name of the tag. I tested this out myself on the Dawn theme and it works as expected:

Hi Liam

Thanks loads for that! It worked a charm. It has even helped me solve another issue at the same time.

Hope you have a fantastic day!

Great to hear Michael - best of luck with the rest of your project and let us know if you run into any other issues!!