How to display collection titles in breadcrumbs on product pages?

Hi,

I have a store with many collections and products - https://incensesticks.com/

So in order to provide the customer easy access to all my products, I want to display a breadcrumb on all pages ( sub-collections and product pages) .

I have added the code for that but the issue is that when I visit the product page, there is no way I can find the collection title as one product comes under many collections.

For eg: I have a collection named “Essential Oils” and there is a product named “Lemon Essential Oil” in it. SO on the product page of Lemon, I want breadcrumb as Home > Essential Oils > Lemon Oil but currently I am just getting Home > Lemon Oil.

Can anyone guide as to what can be done here to achieve the collection name?

Thanks & Regards,

Diana Hiradhar

Hi,

Thanks for your reply!

But I am still not quite sure about what you are saying.

I added the breadcrumb code in the product template. Below is the code:

{%- unless template == ‘index’ or template == ‘cart’ or template == ‘list-collections’ or template == ‘404’ -%}
{%- assign t = template | split: ‘.’ | first -%}

  1. Home
  2. {%- case t -%} {%- when 'page' -%}
  3. {{ page.title }}
  4. {%- when 'product' -%} {%- if collection.url -%}
  5. {{ collection.title | link_to: collection.url }}
  6. {%- endif -%} {%- if product.type -%}
  7. {{ product.type | link_to: product.type.url }}
  8. {%- endif -%}
  9. {{ product.title }}
  10. {%- when 'collection' and collection.handle -%} {%- if current_tags -%}
  11. {{ collection.title | link_to: collection.url }}
  12. {%- capture tag_url -%}{{ collection.url }}/{{ current_tags | join: "+"}}{%- endcapture -%} {{ current_tags | join: " + "}}
  13. {%- else -%}
  14. {{ collection.title }}
  15. {%- endif -%} {%- when 'blog' -%} {%- if current_tags -%}
  16. {{ blog.title | link_to: blog.url }}
  17. {%- capture tag_url -%}{{blog.url}}/tagged/{{ current_tags | join: "+" }}{%- endcapture -%} {{ current_tags | join: " + " }}
  18. {%- else -%}
  19. {{ blog.title }}
  20. {%- endif -%} {%- when 'article' -%}
  21. {{ blog.title | link_to: blog.url }}
  22. {{ article.title }}
  23. {%- else -%}
  24. {{ page_title }}
  25. {%- endcase -%}
{%- endunless -%}

I have added this code in the product template under liquid block.

Can you please elaborate as to what code should I add and where to get the collection name in breadcrumb.

Also, regarding the product url not containing any collection name, I am not sure why that is not coming. I have added the collection name in the product type as well as the collection field on the product page in Admin section . Plz chk the attached screenshots of my navigation and the product pages.

Kindly guide as to how this issue can be resolved.

Many thanks!

Thanks for your reply!

I was able to add the collection name in the url and this is displayed fine on the product page now.

I do have some queries though:

When I search for the product and visit the product page from there then again I do not see the collection name in breadcrumb, just the products name.

Is there a way where I can make the breadcrumb consistent for the product so no matter from where the customer lands on the product page, it will always have same breadcrumb with collection name?

Also how can I have breadcrumb throughout the website for all pages?

Thanks!

Hey,

I was trying this too, where should I find {{ product.url }} ?