I would like to create a ‘back to collection’ link on the top left of each product page that would take the customer back to the collection that product is part of. I’ve tried coding it but it doesn’t show up and when it did, it was in the wrong area.
Hello @jbrielle
Do you still want to do it? if yes, then please share the store url and password (id applied).
So i can check and find the best solution for you ?
I am looking for this functionality also…
Did you find a solution?
TIA, Craig
Yeah. I have best solution for your issue.
you simply need to follow below steps:
-
Go to admin > Online store > edit code.
-
Find the file named “main-product.liquid” if you use dawn theme. otherwise open the file which contains code for the product page.
-
Copy below mentioned code and paste it where you want to show “Back to collection” button or link.
{% for collection in product.collections %}
{% if forloop.index == 1 %}
{% assign collection_url = collection.url %}
{% endif %}
{% endfor %}
Back to Collection
- Don’t forget to save the file after making changes.
Hope this solution works best for your issue.
Was my reply helpful? Click Like to let me know!
Was your question answered? Mark it as an Accepted Solution.
Best Regards
Parth ghelani
Hi Parth,
Thank you so much for your help, it is a perfect solution!!!
Nice to hear it from your. Can you please like and accept the solution as solved.
Thank you !
I am sorry, I don’t know how to ‘accept the solution as solved’…
Hello!
I’m super late but I am using the Origin theme. I see your solution says to add the code where I want the link to appear but what code would I be looking for for placement purposes? I want it to appear in the top left as a link. https://www.shopjbrielle.com/ and gowreu if you need to take a look. I’ll test out the code in the meantime
Hello @jbrielle
I’ve mentioned the code below, you can take code from there and taste it on your store.
If you have any queries regarding that, just dm me.