Liquid, JavaScript, themes, sales channels
Hi,
Just wondering if it is possible to do this...
There aren't many products on the site I'm working on, so within the main navigation the 'STORE' links to /collections/all.
The problem is that if someone visits mysite.com/collections - it takes them to an overview of all of the collections which I don't want.
Is there a way to bypass this with redirects?
Thanks
Hey, @cwilson
If you want your 'STORE' to link to all of the products available on your store as opposed to all of the collections on your store, you can make this change within your navigation settings.
By going to online store > navigation > click on the menu you want to edit > click the edit button beside menu item you want to edit >change the link to 'All Products'. As shown below:
Once you do that, be sure to save your changes. If there is anything else I can help you with, please let me know.
Dirk | Social Care @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Hi Dirk,
Thanks, but that isn't quite what I was looking for. Even though the navigation bar links to 'All Products' if a visitor was to navigate to www.mysite.com/collections/ they would still see a page that I don't want them to see.
I have no need for the page, so, therefore, do not want to spend time having to style it when it is redundant.
Is there a way that I can redirect all traffic that tries to reach /collections/ ?
Thanks
Did you ever get an answer to this? Im not sure why all the Shopify members think a solution is to hide the links....people can still access the page.....google can still index them......
Unfortunately not...
Hi, a bit late to the party 😀
I had the same request from a client. The Shopify redirects don't seem to work with some key pages, like the /collections one.
I made it work by adding a JavaScript redirect in the list-collections.liquid template file in my theme:
<script>
location.href = '/collections/all';
</script>
Hope this helps.
Alex, where exactly would you add the script?
I tried adding at the end or before {% endschema %} of my collection-list.liquid or to list-collections.json - doesn't work, it won't redirect.
Thanks!
Add the following script in the theme.liquid file before </body>
<script>
let url = window.location.href;
if (url.includes('/collections/collection-name')) {
location.href = '/products/productname';
}
</script>
Yes, the following instructions will work for any theme.
1. In your Shopify Admin go to online store > themes > actions > edit code
2. In your theme.liquid file, find the </body> (press CTRL + F or command + F on Mac)
3. paste this code right above the </body> tag:
<script>
if (/collections$/.test(window.location.href)){
var url = `${window.location.href}/all`
window.location.href = url;
}
</script>
Whenever the user lands on a URL ending specifically with "collections" they will be redirected to "collections/all".
Kind regards,
Diego
Hi Diego, this solution definitely helps when someone lands on <store>/collections. However, it does not help when someone adds the '/' at the end, e.g., <store>/collections/
Hey @diego_ezfy , thank you for this. Do you have a solution for what happens when the client puts a / on the end? Your solution works for ABC.com/collections but not ABC.com/collections/
Thank you. Each of our collections represent products that are exclusive for a certain customer. We don't want people to get in a situation where they can see all of our collections. That would be bad.
Do something like following in your theme.liquid by adding a <script></script> block containing following,
// redirect '/collections' or '/collections/' or '/products' or '/products/' to '/pages/our-product-range'
// Shopify navigation redirects won't work for these urls as they are Shopify default urls not controlled by the theme
if (window.location.pathname === '/collections' || window.location.pathname === '/collections/' || window.location.pathname === '/products' || window.location.pathname === '/products/') {
window.location.href = '/pages/our-product-range';
}
Javascript Redirection is not a real 301 as it happens on client side but fortunately indexing will respect this (ref:Redirects and Google Search | Google Search Central | Documentation | Google Developers see lower table saying Permanent)
However it may take a few days to see data propagated on search result page on google
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024