Getting Breadcrumbs working when no collection in url

To improve SEO a while back removed collections from Shopify URL’s.

This has led to the back button on the page now defaulting to a link that goes to the collections/all.

Is there a way to get product collection to display or trigger the liquid code.

Was trying to add breadcrumbs and it isn’t pulling any collection names.

This is the existing code that bypasses to the else option now:

{% if collection.previous_product %}
{% capture prev_url %}{{ collection.previous_product }}{% endcapture %}
{{ ‘products.general.previous_product_html’ | t | link_to: prev_url }}
{% if collection.next_product %}|{% endif %}
{% endif %}

{% if collection.next_product %}
{% capture next_url %}{{ collection.next_product }}{% endcapture %}
{{ ‘products.general.next_product_html’ | t | link_to: next_url }}
{% endif %}

{% if collection %}
Back to collection

{% else %}
< {{ collections.all.title }}

{% endif %}

This is a basic code using for breadcrumb until realized why wasn’t working (I was testing in older version of live store that still had collections in URL):

{% unless template == ‘index’ or template == ‘cart’ or template == ‘list-collections’ %}

Home

{{ collection.title }}
{{ product.title }}

{% endunless %}

Thanks

Hello @CjCj

Steps to Follow How to Create Breadcrumbs:

  1. Create a Collection for a product. Go to Admin → Products → Collections.

  2. Create Metafield for a product. Go to Admin → Settings → Custom Data → Metafields → Products → Add Definition.

  3. Now, Assign This Collection to Metafield we have created above.

  4. Remove “within: Collection” from the URL as breadcrumbs work according to the URL path.


  1. Create and Add a Snippet ‘breadcrumbs.liquid’ and render in ‘theme.liquid’.
'breadcrumbs.liquid’
{% unless template == ‘index’ or template == ‘list-collections’ %}
  
{% endunless %}

Below code conditionally to show breacrumbs metafield on the product page. Also apply filters to URL and breadcrumbs.

{% if template.name == ‘product’ %}
    {% if  product.metafields.custom.breadcrumb_collection %}
      /
  {% endif %}
     {{ product.metafields.custom.breadcrumb_collection | capitalize }}

Just Try above the steps it might be helpful to you:-

1 Like

Thanks for the possible solution, we can’t use metafields unfortunately. As our products are created in a separate program and imported into Shopify. Maybe down the line this will change.