Hide specific pages (and collections?) from search - Refresh 8.0.0

Topic summary

A user’s custom code to hide specific pages from storefront search results stopped working after updating to Refresh theme version 8.0.0. The original implementation used a metafield (custom.hide_from_storefront_search) to filter search results.

Original Issue:

  • Code that previously worked to exclude pages from search no longer functions after theme update
  • User seeks solution to restore metafield functionality or find alternative method

Proposed Solution:
A responder provided modified code that:

  • Checks for hide_from_storefront_search metafield under the seo namespace (instead of custom)
  • Extends functionality to hide both pages AND collections from search
  • Uses conditional checks based on object_type to handle different content types

Key Technical Detail:
The namespace changed from custom to seo in the updated code. Users must ensure their metafield namespace/key matches the code implementation.

Status: Solution proposed but not yet confirmed as resolved by original poster.

Summarized with AI on November 22. AI used: claude-sonnet-4-5-20250929.

I have had this code on my site before (and still have) to hide some pages from search: Solved: Re: How to remove specific pages from storefront search results - Shopify Community

But after I updated the theme last week to Refresh 8.0.0, it no longer works.

  1. Do somebody know how can make my metafields to work again? Or some other easy way to hide pages?
{%- for item in search.results -%}
  {% assign lazy_load = false %}
  {%- if forloop.index > 2 -%}
   {%- assign lazy_load = true -%}
  {%- endif -%}

  {% unless item.metafields.custom.hide_from_storefront_search == 1 %}

  - {%- case item.object_type -%}
      {%- when 'product' -%}
       {%- capture product_settings -%}{%- if section.settings.product_show_vendor -%}vendor,{%- endif -%}title,price{%- endcapture -%}
       {% render 'card-product',
        card_product: item,
        media_aspect_ratio: section.settings.image_ratio,
        show_secondary_image: section.settings.show_secondary_image,
        show_vendor: section.settings.show_vendor,
        show_rating: section.settings.show_rating,
        lazy_load: lazy_load
       %}
      {%- when 'article' -%}
       {% render 'article-card',
        article: item,
        show_image: true,
        show_date: section.settings.article_show_date,
        show_author: section.settings.article_show_author,
        show_badge: true,
        media_aspect_ratio: 1,
        lazy_load: lazy_load
       %}
      {%- when 'page' -%}
     

      

       

        

           ### 
          
             {{ item.title | truncate: 50 | escape }}
          
         
        

        
           {{ 'templates.search.page' | t }}
        

       

      

     

      {%- endcase -%}
  

 {% endunless -%}

{%- endfor -%}

And is it also possible to hide some specific collections from search?

Hi @Kingstone

It seems that the code you provided is a search results template that checks whether a particular metafield named hide_from_storefront_search is set 1 for each search result item. If it is set to 1, the item is not displayed on the search results page. It is also possible to hide specific collections from search by creating a similar metafield for collections and updating the above code to check that metafield for each collection item. You can create a custom metafield for collections in the same way as you did for pages.

Here is the modified code that includes the check for the hide_from_storefront_search metafield for both pages and collections:

{%- for item in search.results -%}
  {% assign lazy_load = false %}
  {%- if forloop.index > 2 -%}
   {%- assign lazy_load = true -%}
  {%- endif -%}

  {% if item.object_type == 'page' %}
    {% unless item.metafields.seo.hide_from_storefront_search == 1 %}
      - ### 
                    {{ item.title | truncate: 50 | escape }}
                
              

              
                  {{ 'templates.search.page' | t }}
              

            

          

        

      

    {% endunless %}
  {% elsif item.object_type == 'collection' %}
    {% unless item.metafields.seo.hide_from_storefront_search == 1 %}
      - ### 
                    {{ item.title | truncate: 50 | escape }}
                
              

              
                  {{ 'templates.search.collection' | t }}
              

            

          

        

      

    {% endunless %}
  {% endif %}

{%- endfor -%}

Note that in the modified code, I am checking for the hide_from_storefront_search metafield with namespace seo for both pages and collections. If you have used a different namespace or key for your metafield, make sure to update the code accordingly.

We hope this can help you!