Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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
I tried this and it worked for me.
First, create a new collection and name it "all". Add any or all of the products you want to show.
Second, add this code to your theme.liquid file, right after the <head> tag:
{% if request.path == '/collections' %}
<script>window.location.href="/collections/all"</script>
{% endif %}
That's it. Now when someone goes to mysite.com/collections, they will see mysite.com/collections/all
This worked for me, except I didn't even need to add any code to the theme.liquid file for my theme.
By naming a collection as "all" it over wrote Shopify's default "all" collection. Now instead of all the products showing if I user goes to the top level of the collections, it shows the products that I want to show.
OK, thanks! But that didn't work for me. I had to do it as I described above. Weird, that some stuff works for some sites, and not others ... have seen that with other stuff, too ....
This code solved everything for me:
<script>
if (/collections\/?$/.test(window.location.href)){
var url = window.location.href.replace(/\/?$/, '') + '/all';
window.location.href = url;
} else if (/products\/?$/.test(window.location.href)){
window.location.href = window.location.origin + '/collections/all';
}
</script>
It redirects /products, /products/, /collections, and /collections/ to /collections/all
Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024