To prevent certain pages from being indexed by search engines, you'll need to make some adjustments to the theme's code.
This situation is common if you have content that you create for special promotions or landing pages or for pages that you create that are only meant to "feed" other pages, such as homepage featured content or size charts.
In This Article
- Blocking a handful of specific pages
- Blocking a large number of pages
- Blocking products, collections or articles
- Blocking a large number of pages, collections, articles or products
Blocking a handful of specific pages
Step 1: First, open the theme editor using these steps. Select the file theme.liquid.
Step 2: Next, locate this code, which is typically around Line 10:
<meta name="robots" content="index,follow">
Replace it with this code:
{% if page.handle == "page-handle-1" or page.handle == "page-handle-2" %} <meta name="robots" content="noindex,nofollow"> {% else %} <meta name="robots" content="index,follow"> {% endif %}
Step 3: You will need to replace " page-handle-1" and "page-handle-2" with the handles of the pages you'd like to be blocked. To determine your page handle, see these instructions.
If you have more than two pages that need to be blocked, you can repeat this code:
or page.handle == "page-handle"
Just replace "page-handle" with the page handle of each page you want to block.
Blocking a large number of pages
If you anticipate having a large number of pages that you want to block from being indexed, this approach might be a bit impractical and could, in extreme cases, cause performance issues.
Because of this, there is a method that you can use that will block all pages that have a handle prefixed with a certain string of text.
{% if page.handle contains "your-text-" %} <meta name="robots" content="noindex,nofollow"> {% else %} <meta name="robots" content="index,follow"> {% endif %}
In this example, you will need to replace "your-text-" with a unique prefix that will NOT appear in anywhere in the handles of pages you WANT to be indexed.
Something like "cb-" (short for "content block") is a good choice since it's unlikely you'll have a page with that in its handle.
Then, for any pages you want to block from being indexed, you'll need to adjust the page handle in the SEO section at the bottom of the product management page to be "your-text-" followed by a unique word or phrase.
For example, if you are trying to block a page named "size-chart" from being indexed, change its handle to "cb-size-chart" and save.
Blocking products, collections or articles
To block specific products, collections or blog articles from being indexed, you can use a similar approach.
The code is almost the same as the examples above, but instead of page.handle, you should use collection.handle, product.handle or article.handle in its place.
Blocking a large number of pages, collections, articles or products
If you need to block a large number of an assortment of pages, collections, articles or products, you can use this code:
{% if page.handle contains "your-text-" or collection.handle contains "your-text-" or product.handle contains "your-text-" or article.handle contains "your-text-" %} <meta name="robots" content="noindex,nofollow"> {% else %} <meta name="robots" content="index,follow"> {% endif %}
Again, for this approach, change "your-text-" to a unique prefix and then modify the handles of every page, article, product or collection you want to block to start with that prefix.
Advanced Customization
Please note that this tutorial is considered an advanced customization and is not supported by Out of the Sandbox. If you encounter difficulties with this, please contact a third party developer for more troubleshooting, customization or functionality.