Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I am trying to automatically loop over the products in an unlisted collection, extract their handle and then add them to the Disallow list of our robots.txt. I wrote some code that I thought would do this, but all I am getting is an empty line in our robots.txt. Where am I going wrong? Is it because the collection is unlisted?
{%- if group.user_agent.value == '*' -%} {% for product in collections['discontinued-products'].products %} {% assign discon = product.handle %} {% assign noindexdiscon = 'Disallow: /products' | append: discon %} {{ noindexdiscon }} {% endfor %} {%- endif -%}
I am doing this because Shopify doesn't allow me to send a 410 Gone code, so I figured this is the easiest way to make search engines remove discontinued products from their indexes. We don't track inventory in our store, so I am currently marking discontinued products by enabling Track Inventory and leaving the value as 0.
After a month or two, I plan on archiving the product and setting up a redirect to our search results page, with a search query related to the product.
If someone knows a better way to automatically detect out of stock products and add them to the disallow list, I would love to hear it. I am an amateur when it comes to Liquid coding.
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025