Anyone familiar with Shopify knows that collections are a key part of organizing your product catalog. But managing your store effectively often means you need tons of collections, which can result in a lot of unnecessary pages being indexed by search engines. This can lead to issues like duplicate content or even cannibalization of your rankings in Google search results. Unfortunately, Shopify doesn’t offer an easy way for merchants to control which collections get indexed and which don’t. You can use the robots.txt file or opt for paid apps, but here’s our approach – simple, cost-effective, and no messy SEO consequences.
Our method is super easy and can be implemented by anyone. With just a little code and metafields, you’ll be able to control which collections shouldn’t be indexed. Here’s how:
Step 1: Create the Metafield
- First, create a new metafield for collections. Go to Settings (bottom left) -> Custom data -> Collections -> Add new definition.
- Name the definition Noindex (or whatever you prefer).
- Set the Namespace and key – this is important because we’ll refer to this metafield later in the code. Shopify will generate it automatically for you. If you choose Noindex as the name, it’ll look like this: custom.noindex.
- For the metafield type, choose: True or false
Step 2: Add Some Code
Now that we’ve set up the metafield, it’s time to add some code. Don’t worry, it’s easy. Here’s what to do:
- Go to your Online Store -> Themes (your active theme) -> In the three dots menu […] before the Customize button, select Edit code.
- Look for the theme.liquid file and open it.
- At the very top of the file, add this code:
{% if collection.metafields.custom.noindex == true %}
<meta name=“robots“ content=“noindex, follow“>
{% endif %}
This is a basic check if the metafield value is True. If it is, it will add a noindex tag to the page’s head, telling search engines not to index that collection. We recommend using follow instead of nofollow because it tells bots to follow links on the page. If you used a different Namespace and key when creating your metafield, just change the code here to match:
collection.metafields.custom.yourname
Save the changes, and you’re done.
Now all you need to do is activate this metafield on the collections you want to hide from search engines, and they won’t get indexed anymore. You can now create hidden collections freely, without worrying about them showing up in search results.
Do the Same for your Products
You can use a similar approach for your products by creating a similar metafield. Just add an extra block of code, and use the following:
{% if collection.metafields.custom.noindex == true %}
<meta name=“robots“ content=“noindex, follow“>
{% endif %}
Коментирай