How to ignore auto-collections in breadcrumbs?

https://0db1d3-5b.myshopify.com/products/third-product

I’m using the code below to show breadcrumbs on a product page.

How can I modify this code, so that it ignores collections which were added as a result of tags (auto-collections) and only considers manual collections or simply considers only the very first collection?

It seems that Shopify lists manual collections first and then adds any auto-collections after that.

{%- style -%}
    .breadcrumbs {
        padding: 0rem;
        color: {{ settings.breadcrumb_text_color }};
    }

    .breadcrumbs li {
        display: inline-block;
    }

    .breadcrumbs a {
        text-decoration: none;
        /*Will put liquid customization here*/
        font-size: 15px;
        color: inherit;
    }

      .breadcrumbs a:hover {
        text-decoration: underline;
    }

      .breadcrumbs a:last-child {
        display: none;
    }

    .breadcrumb-delimeter:not(:last-child):after {
        {%- if settings.breadcrumb_delimeter == "angle_right" -%}
            content: "›";
            font-size: 18px;
        {%- elsif settings.breadcrumb_delimeter == "slash" -%}
            content: "/";
            font-size: 16px;
        {%- endif -%}
        display: inline-block;
        margin-left: .75rem;
        margin-right: 0.50rem;
        speak: none;
    }

    .breadcrumbs [aria-current="page"] {
        color: inherit;
        font-weight: normal;
        text-decoration: none;
    }

    
{%- endstyle -%}

    {%- unless template == 'index' or template == 'cart' -%}
    Home
    {%- case template.name -%}
        {%- when 'article' -%}
        {%- for link in linklists.main-menu.links -%}
            {%- if link.url == blog.url -%}
                 
                {{ link.title | link_to: link.url }}
                {% break %}
            {%- endif -%}
        {%- endfor -%}
            
            {{ article.title }}
        {%- when "product" -%}
            {%- capture product_url_string -%}
            {%- for collection in product.collections -%}
                {{collection.url }}|
            {%- endfor -%}
            {%- endcapture -%}
    
            {%- assign object_url_string = product_url_string | append: product.url -%}
        
            {%- assign object_urls = object_url_string | split: '|' -%}
            {%- capture linklist_titles_str -%}{%- for linklist in linklists -%}{{ linklist.title | handleize }}|{%- endfor -%}{%- endcapture -%}
            {%- assign str_size = linklist_titles_str | size | minus: 1 -%}
            {%- assign linklist_titles_str = linklist_titles_str | slice: 0, str_size -%}
            {%- assign linklist_titles = linklist_titles_str | split: '|' -%}
        
        
        {%- assign level = 1 -%}
        {%- for link in linklists.main-menu.links -%}
            {%- assign link_handle = link.title | handle -%}
            {%- assign link_titles = link_titles | append: link.title | append: '|' -%}
            {%- assign link_urls = link_urls | append: link.url | append: '|' -%}
            {%- assign link_levels = link_levels | append: level | append: '|'  -%}
            {%- assign link_parents = link_parents | append: 'main-menu' | append: '|'  -%}
            {%- assign link_handles = link_handles | append: link_handle | append: '|' -%}
        
            {%- if linklist_titles contains link_handle -%} 
        
            {%- for clink in linklists[link_handle].links -%}
                {%- if forloop.first == true -%}
                {%- assign level = level | plus: 1 -%}
                {%- endif -%}
                {% assign clink_handle = clink.title | handle %}
                {%- assign link_titles = link_titles | append: clink.title | append: '|' -%}
                {%- assign link_urls = link_urls | append: clink.url | append: '|' -%}
                {%- assign link_levels = link_levels | append: level | append: '|'  -%}
                {%- assign link_parents = link_parents | append: link_handle | append: '|'  -%}
                {%- assign handle = link.title | handleize -%} 
                {%- assign link_handles = link_handles | append: clink_handle | append: '|' -%}
        
                {%- if linklist_titles contains clink_handle -%}
        
                    {%- for gclink in linklists[clink_handle].links -%}
                        {%- if forloop.first == true -%}
                        {%- assign level = level | plus: 1 -%}
                        {%- endif -%}
        
                        {% assign gclink_handle = gclink.title | handle %}
                        {%- assign link_titles = link_titles | append: gclink.title | append: '|' -%}
                        {%- assign link_urls = link_urls | append: gclink.url | append: '|' -%}
                        {%- assign link_levels = link_levels | append: level | append: '|'  -%}
                        {%- assign link_parents = link_parents | append: gclink_handle | append: '|'  -%}
                        {%- assign link_handles = link_handles | append: gclink_handle | append: '|' -%}

                        {%- if forloop.last == true -%}
                        {%- assign level = level | minus: 1 -%}
                        {%- endif -%}
                    {%- endfor -%}
        
                {%- endif -%}
                {%- if forloop.last == true -%}
                {%- assign level = level | minus: 1 -%}
                {%- endif -%}
            {%- endfor -%}
            {%- endif -%}
        {%- endfor -%}
        
        {%- comment -%} CONVERT TO ARRAYS {%- endcomment -%}
        {%- assign str_size = link_levels | size | minus: 1 -%}
        {%- assign llevels = link_levels | slice: 0, str_size | split: '|' -%}
        
        {%- assign str_size = link_titles | size | minus: 1 -%}
        {%- assign ltitles = link_titles | slice: 0, str_size | split: '|' -%}
        
        {%- assign str_size = link_handles | size | minus: 1 -%}
        {%- assign lhandles = link_handles | slice: 0, str_size | split: '|' -%}
        
        {%- assign str_size = link_parents | size | minus: 1 -%}
        {%- assign lparents = link_parents | slice: 0, str_size | split: '|' -%}
        
        {%- assign str_size = link_urls | size | minus: 1 -%}
        {%- assign lurls = link_urls | slice: 0, str_size | split: '|' -%}
        
        {%- assign depth = '3' -%}
        {%- assign bc3_parent_list_handle = '' %}
        
        {%- for url in lurls -%}
            {%- if object_urls contains url and llevels[forloop.index0] == depth -%}
            {%- unless url == product.url or url == collection.url -%}
                {%- capture bc3 -%}{{ ltitles[forloop.index0] | link_to: url, ltitles[forloop.index0] }}{%- endcapture -%}
            {%- endunless -%}
            {%- assign bc3_parent_list_handle = lparents[forloop.index0] -%}
            {%- assign bc3_list_handle = lhandles[forloop.index0] -%}
            {% break %}
            {%- endif -%}
        {%- endfor -%}

        {%- assign depth = '2' -%}
        {%- assign bc2_parent_list_handle = '' %}
        
        {%- if bc3_parent_list_handle == '' -%} 
            {%- for url in lurls -%}
            {%- if llevels[forloop.index0] == depth -%}
                {%- if object_urls contains url -%} 
                {%- unless url == product.url or url == collection.url -%}
                    {%- capture bc2 -%}{{ ltitles[forloop.index0] | link_to: url, ltitles[forloop.index0] }}{%- endcapture -%}
                {% endunless %}
                {%- assign bc2_parent_list_handle = lparents[forloop.index0] -%}
                {%- break -%}
                {%- endif -%}
            {%- endif -%}
            {%- endfor -%} 
        {%- else -%}

            {%- for list_handle in lhandles -%}
            {%- if list_handle == bc3_parent_list_handle -%}
                {% assign bc2_list_handle = list_handle %}
                {%- assign bc2_parent_list_handle = lparents[forloop.index0] -%}
                {%- assign bc2_list_title = ltitles[forloop.index0] -%}
                {%- for bc2_sibling_link in linklists[bc2_parent_list_handle].links -%}
                {%- assign bc2_sibling_title_handleized = bc2_sibling_link.title | handle -%}
                {% if bc2_sibling_title_handleized == bc2_list_handle %}
                    {%- capture bc2 -%}{{ bc2_sibling_link.title | link_to: bc2_sibling_link.url, bc2_sibling_link.title }}{%- endcapture -%}
                    {% break %}
                {%- endif -%}
                {%- endfor -%}
                {% break %}
            {%- endif -%}
            {%- endfor -%}
        {%- endif -%}
        
        {%- assign depth = depth | minus: 1 | append: '' -%}
        {%- assign bc1_parent_list_handle = '' %}
        
        {%- if bc2_parent_list_handle == '' -%} 
            {% for url in lurls %}
            {%- if object_urls contains url and llevels[forloop.index0] == depth -%}
                {%- unless url == product.url or url == collection.url -%}
                {%- capture bc1 -%}{{ ltitles[forloop.index0] | link_to: url, ltitles[forloop.index0] }}{%- endcapture -%}
                {% endunless %}
                {%- assign bc1_parent_list_handle = lparents[forloop.index0] -%}
                {%- break -%}
            {%- endif -%}
            {%- endfor -%}
        
        {%- else -%}
            {%- for list_handle in lhandles -%}
            {%- if bc2_parent_list_handle == list_handle -%}
                {% assign bc1_list_handle = list_handle %}
                {%- assign bc1_parent_list_handle = lparents[forloop.index0] -%}
                {%- assign bc1_title = ltitles[forloop.index0] -%}
                {%- for bc1_sibling_link in linklists[bc1_parent_list_handle].links -%}
                {%- assign bc1_sibling_title_handleized = bc1_sibling_link.title | handle -%}
                {% if bc1_sibling_title_handleized == bc1_list_handle %}
                    {%- capture bc1 -%}{{ bc1_sibling_link.title | link_to: bc1_sibling_link.url, bc1_sibling_link.title }}{%- endcapture -%} 
                    {% break %}
                {%- endif -%}
                {%- endfor -%}
            {%- endif -%}
            {%- endfor -%}
        {%- endif -%}
       
            {%- if bc1 -%}
             
            {{ bc1 }}
            {%- endif -%}
            {%- if bc2 -%}
            
            {{ bc2 }}
            {%- endif -%}
            {%- if bc3 -%}
            
            {{ bc3 }}
            {%- endif -%}
        
            
            {{ product.title }}
        {%- else -%}
            {% for link in linklists.main-menu.links %}
                {% if link.child_active or link.active %}
                 
                    
                    {{ link.title | escape }}  
                    
                    {% for clink in link.links %}
                    {% if clink.child_active or clink.active %}
                    
                        
                        {{ clink.title | escape }} 
                        
                        {% for gclink in clink.links %}
                        {% if gclink.child_active or gclink.active %}
                            
                            
                            {{ gclink.title | escape }} 
                            
                        {% endif %}
                        {%- endfor -%}
                    {% endif %}
                    {%- endfor -%}
                {% endif %}
            {%- endfor -%}
        {%- endcase -%}
    {%- endunless -%}

You can try this breadcrumbs solution: https://youtu.be/B4_STWW3LSk

It uses a dedicated menu (doesn’t have to be the navigation menu live on your store) to build out exactly how you want your breadcrumbs to look, so you can include/exclude the collections you want. You can even do some custom structures, like nesting your collections.

Thanks for the effort, but it doesn’t solve the issue that I’ve described in my OP and this solution seems to have number of other issues:

  1. Unable to move the section around the theme freely. It forces the user to place it directly into the theme file, which means this will take the whole widget of the page not allow you to place into the product information section, above the product title, just like I have in my example. Most likely there is a workaround, but at least it’s not clear for a non-developer user like me.

  2. Doesn’t have an option to hide the name of the product as the last element of the crumbs. That would be ideal as the whole point of it is just to show the path to the page you’re already on and there is no need to repeat the h1 of the page in the breadcrumbs.

  3. I was not able to get it to show anything in the path, while selected the main navigation menu as the source. I’m not sure if that’s because I’m linking the product to multiple collection both manually and with tags (see image) or some other issue.

Since I couldn’t find a better solution, this updated version of the code simply has a list of tags (collections) to ignore. It works perfectly fine for me and hopefully will work for someone else as well

{%- style -%}
    .breadcrumbs {
        padding: 0rem;
        color: {{ settings.breadcrumb_text_color }};
    }

    .breadcrumbs li {
        display: inline-block;
    }

    .breadcrumbs a {
        text-decoration: none;
        /*Will put liquid customization here*/
        font-size: 15px;
        color: inherit;
    }

      .breadcrumbs a:hover {
        text-decoration: underline;
    }

      .breadcrumbs a:last-child {
        display: none;
    }

    .breadcrumb-delimeter:not(:last-child):after {
        {%- if settings.breadcrumb_delimeter == "angle_right" -%}
            content: "›";
            font-size: 18px;
        {%- elsif settings.breadcrumb_delimeter == "slash" -%}
            content: "/";
            font-size: 16px;
        {%- endif -%}
        display: inline-block;
        margin-left: .75rem;
        margin-right: 0.50rem;
        speak: none;
    }

    .breadcrumbs [aria-current="page"] {
        color: inherit;
        font-weight: normal;
        text-decoration: none;
    }

    
{%- endstyle -%}

{% assign collections_to_ignore = "Ramadan, Pre-Worn, New In, Jewelry, Exclusive, Clothing, Bridal, Event" | split: ", " %}

    {%- unless template == 'index' or template == 'cart' -%}
    Home
    {%- case template.name -%}
        {%- when 'article' -%}
        {%- for link in linklists.main-menu.links -%}
            {%- if link.url == blog.url -%}
                 
                {{ link.title | link_to: link.url }}
                {% break %}
            {%- endif -%}
        {%- endfor -%}
            
            {{ article.title }}
        {%- when "product" -%}
{%- capture product_url_string -%}
    {%- for collection in product.collections -%}
        {%- unless collections_to_ignore contains collection.title -%}
            {{ collection.url }}|
        {%- endunless -%}
    {%- endfor -%}
{%- endcapture -%}
    
            {%- assign object_url_string = product_url_string | append: product.url -%}
        
            {%- assign object_urls = object_url_string | split: '|' -%}
            {%- capture linklist_titles_str -%}{%- for linklist in linklists -%}{{ linklist.title | handleize }}|{%- endfor -%}{%- endcapture -%}
            {%- assign str_size = linklist_titles_str | size | minus: 1 -%}
            {%- assign linklist_titles_str = linklist_titles_str | slice: 0, str_size -%}
            {%- assign linklist_titles = linklist_titles_str | split: '|' -%}
        
        
        {%- assign level = 1 -%}
        {%- for link in linklists.main-menu.links -%}
            {%- assign link_handle = link.title | handle -%}
            {%- assign link_titles = link_titles | append: link.title | append: '|' -%}
            {%- assign link_urls = link_urls | append: link.url | append: '|' -%}
            {%- assign link_levels = link_levels | append: level | append: '|'  -%}
            {%- assign link_parents = link_parents | append: 'main-menu' | append: '|'  -%}
            {%- assign link_handles = link_handles | append: link_handle | append: '|' -%}
        
            {%- if linklist_titles contains link_handle -%} 
        
            {%- for clink in linklists[link_handle].links -%}
                {%- if forloop.first == true -%}
                {%- assign level = level | plus: 1 -%}
                {%- endif -%}
                {% assign clink_handle = clink.title | handle %}
                {%- assign link_titles = link_titles | append: clink.title | append: '|' -%}
                {%- assign link_urls = link_urls | append: clink.url | append: '|' -%}
                {%- assign link_levels = link_levels | append: level | append: '|'  -%}
                {%- assign link_parents = link_parents | append: link_handle | append: '|'  -%}
                {%- assign handle = link.title | handleize -%} 
                {%- assign link_handles = link_handles | append: clink_handle | append: '|' -%}
        
                {%- if linklist_titles contains clink_handle -%}
        
                    {%- for gclink in linklists[clink_handle].links -%}
                        {%- if forloop.first == true -%}
                        {%- assign level = level | plus: 1 -%}
                        {%- endif -%}
        
                        {% assign gclink_handle = gclink.title | handle %}
                        {%- assign link_titles = link_titles | append: gclink.title | append: '|' -%}
                        {%- assign link_urls = link_urls | append: gclink.url | append: '|' -%}
                        {%- assign link_levels = link_levels | append: level | append: '|'  -%}
                        {%- assign link_parents = link_parents | append: gclink_handle | append: '|'  -%}
                        {%- assign link_handles = link_handles | append: gclink_handle | append: '|' -%}

                        {%- if forloop.last == true -%}
                        {%- assign level = level | minus: 1 -%}
                        {%- endif -%}
                    {%- endfor -%}
        
                {%- endif -%}
                {%- if forloop.last == true -%}
                {%- assign level = level | minus: 1 -%}
                {%- endif -%}
            {%- endfor -%}
            {%- endif -%}
        {%- endfor -%}
        
        {%- comment -%} CONVERT TO ARRAYS {%- endcomment -%}
        {%- assign str_size = link_levels | size | minus: 1 -%}
        {%- assign llevels = link_levels | slice: 0, str_size | split: '|' -%}
        
        {%- assign str_size = link_titles | size | minus: 1 -%}
        {%- assign ltitles = link_titles | slice: 0, str_size | split: '|' -%}
        
        {%- assign str_size = link_handles | size | minus: 1 -%}
        {%- assign lhandles = link_handles | slice: 0, str_size | split: '|' -%}
        
        {%- assign str_size = link_parents | size | minus: 1 -%}
        {%- assign lparents = link_parents | slice: 0, str_size | split: '|' -%}
        
        {%- assign str_size = link_urls | size | minus: 1 -%}
        {%- assign lurls = link_urls | slice: 0, str_size | split: '|' -%}
        
        {%- assign depth = '3' -%}
        {%- assign bc3_parent_list_handle = '' %}
        
        {%- for url in lurls -%}
            {%- if object_urls contains url and llevels[forloop.index0] == depth -%}
            {%- unless url == product.url or url == collection.url -%}
                {%- capture bc3 -%}{{ ltitles[forloop.index0] | link_to: url, ltitles[forloop.index0] }}{%- endcapture -%}
            {%- endunless -%}
            {%- assign bc3_parent_list_handle = lparents[forloop.index0] -%}
            {%- assign bc3_list_handle = lhandles[forloop.index0] -%}
            {% break %}
            {%- endif -%}
        {%- endfor -%}

        {%- assign depth = '2' -%}
        {%- assign bc2_parent_list_handle = '' %}
        
        {%- if bc3_parent_list_handle == '' -%} 
            {%- for url in lurls -%}
            {%- if llevels[forloop.index0] == depth -%}
                {%- if object_urls contains url -%} 
                {%- unless url == product.url or url == collection.url -%}
                    {%- capture bc2 -%}{{ ltitles[forloop.index0] | link_to: url, ltitles[forloop.index0] }}{%- endcapture -%}
                {% endunless %}
                {%- assign bc2_parent_list_handle = lparents[forloop.index0] -%}
                {%- break -%}
                {%- endif -%}
            {%- endif -%}
            {%- endfor -%} 
        {%- else -%}

            {%- for list_handle in lhandles -%}
            {%- if list_handle == bc3_parent_list_handle -%}
                {% assign bc2_list_handle = list_handle %}
                {%- assign bc2_parent_list_handle = lparents[forloop.index0] -%}
                {%- assign bc2_list_title = ltitles[forloop.index0] -%}
                {%- for bc2_sibling_link in linklists[bc2_parent_list_handle].links -%}
                {%- assign bc2_sibling_title_handleized = bc2_sibling_link.title | handle -%}
                {% if bc2_sibling_title_handleized == bc2_list_handle %}
                    {%- capture bc2 -%}{{ bc2_sibling_link.title | link_to: bc2_sibling_link.url, bc2_sibling_link.title }}{%- endcapture -%}
                    {% break %}
                {%- endif -%}
                {%- endfor -%}
                {% break %}
            {%- endif -%}
            {%- endfor -%}
        {%- endif -%}
        
        {%- assign depth = depth | minus: 1 | append: '' -%}
        {%- assign bc1_parent_list_handle = '' %}
        
        {%- if bc2_parent_list_handle == '' -%} 
            {% for url in lurls %}
            {%- if object_urls contains url and llevels[forloop.index0] == depth -%}
                {%- unless url == product.url or url == collection.url -%}
                {%- capture bc1 -%}{{ ltitles[forloop.index0] | link_to: url, ltitles[forloop.index0] }}{%- endcapture -%}
                {% endunless %}
                {%- assign bc1_parent_list_handle = lparents[forloop.index0] -%}
                {%- break -%}
            {%- endif -%}
            {%- endfor -%}
        
        {%- else -%}
            {%- for list_handle in lhandles -%}
            {%- if bc2_parent_list_handle == list_handle -%}
                {% assign bc1_list_handle = list_handle %}
                {%- assign bc1_parent_list_handle = lparents[forloop.index0] -%}
                {%- assign bc1_title = ltitles[forloop.index0] -%}
                {%- for bc1_sibling_link in linklists[bc1_parent_list_handle].links -%}
                {%- assign bc1_sibling_title_handleized = bc1_sibling_link.title | handle -%}
                {% if bc1_sibling_title_handleized == bc1_list_handle %}
                    {%- capture bc1 -%}{{ bc1_sibling_link.title | link_to: bc1_sibling_link.url, bc1_sibling_link.title }}{%- endcapture -%} 
                    {% break %}
                {%- endif -%}
                {%- endfor -%}
            {%- endif -%}
            {%- endfor -%}
        {%- endif -%}
       
            {%- if bc1 -%}
             
            {{ bc1 }}
            {%- endif -%}
            {%- if bc2 -%}
            
            {{ bc2 }}
            {%- endif -%}
            {%- if bc3 -%}
            
            {{ bc3 }}
            {%- endif -%}
        
            
            {{ product.title }}
        {%- else -%}
            {% for link in linklists.main-menu.links %}
                {% if link.child_active or link.active %}
                 
                    
                    {{ link.title | escape }}  
                    
                    {% for clink in link.links %}
                    {% if clink.child_active or clink.active %}
                    
                        
                        {{ clink.title | escape }} 
                        
                        {% for gclink in clink.links %}
                        {% if gclink.child_active or gclink.active %}
                            
                            
                            {{ gclink.title | escape }} 
                            
                        {% endif %}
                        {%- endfor -%}
                    {% endif %}
                    {%- endfor -%}
                {% endif %}
            {%- endfor -%}
        {%- endcase -%}
    {%- endunless -%}