How to target /blogs or /blogs/blog directory through conditional tag?

Topic summary

A developer seeks a conditional tag to target Shopify’s /blogs/ or /blogs/blog directory within a header.liquid file.

Solution Provided:

  • Use the global template variable with the contains operator
  • Suggested code: {% if template contains 'blogs' or template contains 'blog' %}
  • This conditional can be used anywhere in theme files, not just specific locations
  • Alternative approach: Check if the URL or tag contains /blogs/

Outcome:
The solution successfully resolved the issue. The original poster confirmed it works after fixing additional bugs in their conditional code.

Summarized with AI on November 23. AI used: claude-sonnet-4-5-20250929.

Is there any conditional tag to target /blogs/ or /blogs/blog directory?

        {% liquid
            **if blogs**
                assign blog_menu = section.settings.blog_menu
                assign mobile_menu = section.settings.mobile_menu
                if mobile_menu == blank
                    assign menu = blog_menu
                else
                    assign menu = mobile_menu
                endif
            
            else
                assign main_menu = section.settings.main_menu
                assign mobile_menu = section.settings.mobile_menu
                
                if mobile_menu == blank
                    assign menu = main_menu
                else
                    assign menu = mobile_menu
                endif
            endif
        %}

Hi @elliyas

May I suggest code blelow

{% if template contains 'blogs' or template contains 'blog' %}
insert your code here
{% endif %}
2 Likes

Thank you for your quick answer. I am editing in header.liquid file.

Hi @elliyas

  • template is global variable. So you can use anywhere.

  • If you check a tag or an url that has ‘/blogs/’. You only need check

if tag contains '/blogs/' or tag contains 'blog'

endif

the same for url

Thank you so much for your effort and time! It works finally. I had some other bugs in my code. After fixing that and implementing your conditional code, I have achieved goal. :blush: