Context
Discount Ninja offers users the ability to select products using a collection. Collections are a convenient way to point to a group of products that you have either manually selected (manual collection) or selected using a rule (smart collection).
Online Store sales channel
For collections to be visible to Discount Ninja they need to be published on the Online Store sales channel.
This allows Discount Ninja to understand which collections each of your products belong to when applying discounts on the storefront.
Problem
When a collection is published on the Online Store sales channel it becomes:
discoverable on search engine (i.e. Google)
discoverable for users when searching your site
Solution
Disallow crawling
To avoid that the collection becomes discoverable on search engines you can:
Tag your collections with the tag
hidden
Add the following code at the top of your collection Liquid template in your theme:
{%- if collection.tags contains 'hidden' -%}
<meta name="robots" content="noindex, nofollow">
<script>window.location.href="/"</script>
{%- endif %}
This code will be triggered if the collection has a tag named hidden
. It will:
Instruct search engines not to index this page
Redirect users to your home page when they land
Hide from search
Find the collection template that contains the for
loop that loops over the search results. Place the following script inside that for loop:
{%- if search_result.object_type == 'collection' -%}
{%- if search_result.tags contains 'hidden' -%}
{%- continue -%}
{%- endif -%}
{%- endif -%}
This script detects search results that are collections with a specific tag (in the above example hidden
) and filters them out. That is to say, the collection is not rendered in the search results.
The above script expects to be placed in a for loop that loops over the search results with the variable name search_result
. Change the variable name if it is different.