Disable ?sort_by=best-selling Function

New Member
1 0 1

I do not want my competitors to be able to view my best selling products. I have seen this disabled on other stores and they get redirected to the homepage.. or another page.

How can I disable people from searching /collections/all?sort_by=best-selling

Shopify Staff
Shopify Staff
47 0 35

Hey Peak Vibrations!

Chantal, Shopify Guru here to help!

I've had success with this by adding this code:

if(document.location.href.indexOf('https://wearepeakvibrations.com/collections/all?sort_by=best-selling') > -1) { 
document.location.href = 'https://wearepeakvibrations.com/collections/all';

to the <head> section of the theme.liquid file of a theme. You can change the URL for document.location.href = 'URL' to whichever page you'd like for visitors to be redirected to when they try to visit the URL /collections/all?sort_by=best-selling on your site.

Hope this helps!

Chantal, Shopify Guru

Chantal, Shopify Guru
New Member
2 0 0

There is a big red flag that says this post is outdated, but I can't find a "current" solution.  Will this still work?


4 0 1

Works for me. Make sure you change the site URL.

Shopify Expert
10360 158 2009

Here's a Liquid based approach if you want to avoid using JavaScript.

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.

★ http://freakdesign.com.au ★
Shopify Partner
15 1 11

One other approach you could try is to just customize your all collection.  In theory most people will be looking at your ALL collection to see the overall best sellers in your shop.

Basically, you can make a custom version of your ALL collection and only put a subset of your products in there that you control.

I summarized the three approaches discussed in this thread over on my blog if you'd like to read more:

⭐️ Flair product badges https://apps.shopify.com/flair ⭐️ Best Sellers - https://apps.shopify.com/best-sellers
New Member
2 0 3

Thanks for posting this @Jason .


It boggles my mind that Shopify is so careless with its' customers' sensitive, proprietary data. This should not be built into the platform.


Another good practice is to make sure that these pages (sort_by, search, current_tags) properly point to the original, canonical version - or are no-index'd.


{% if template contains 'search' %}
<meta name="robots" content="noindex">
{% elsif request.path contains '/types' %}
<meta name="robots" content="noindex">
{% elsif template contains 'collection' and current_tags %}
<meta name="robots" contents="noindex">
{% elsif collection.sort_by contains "best-selling" %}
<meta name="robots" contents="noindex">
{% endif %}

Otherwise you have search engines trying to index pages that SHOULD NOT BE INDEXED.

New Member
2 0 3

Also, just to make sure the freakdesign.com.au content doesn't fall victim to link rot, here's the key part of that page: 


{% if collection.sort_by == 'best-selling' %}
{% else %}
  <!-- your original collection.liquid code in here -->
{% endif %}


New Member
2 0 1

Where would you insert this code?


Thank you!

New Member
1 0 1

I do something similar except instead of 'Nope' I force a sort by price... although you could force it by any filter criteria. Then also remove the Best Seller sort feature.


Here's an example of collection.liquid (yours may vary depending on theme):

{%- comment -%}
  Assuming the contents of the collection.liquid template can be found in /snippets/collection-template.liquid
{%- endcomment -%}

{% if collection.sort_by == 'best-selling' %}
  {% include 'collection-template' current_pagination_limit: settings.pagination_limit | sort: 'price'%}
{% else %}
  {% include 'collection-template' current_pagination_limit: settings.pagination_limit %}
{% endif %}

And the toolbar area of a collection (various places depending on the theme) you can just comment out the best sellers:

  <select class="sort-position">
    <option value="manual"{% if collection.default_sort_by == 'manual' %} selected{% endif %}>{{ 'collections.sorting.featured' | t }}</option>
    <option value="title-ascending"{% if collection.default_sort_by == 'title-ascending' %} selected{% endif %}>{{ 'collections.sorting.az' | t }}</option>
    <option value="title-descending"{% if collection.default_sort_by == 'title-descending' %} selected{% endif %}>{{ 'collections.sorting.za' | t }}</option>
    <option value="created-ascending"{% if collection.default_sort_by == 'created-ascending' %} selected{% endif %}>{{ 'collections.sorting.date_ascending' | t }}</option>
    <option value="created-descending"{% if collection.default_sort_by == 'created-descending' %} selected{% endif %}>{{ 'collections.sorting.date_descending' | t }}</option>
    <option value="price-ascending"{% if collection.default_sort_by == 'price-ascending' %} selected{% endif %}>{{ 'collections.sorting.price_ascending' | t }}</option>
    <option value="price-descending"{% if collection.default_sort_by == 'price-descending' %} selected{% endif %}>{{ 'collections.sorting.price_descending' | t }}</option>
    <!-- <option value="best-selling"{% if collection.default_sort_by == 'best-selling' %} selected{% endif %}>{{ 'collections.sorting.best_selling' | t }}</option> -->

These two things combined make it REALLY hard for anyone to know what the bestsellers are.