How can I hide specific pages from store search results?

How can I hide specific pages from store search results?

mrsilver123
Shopify Partner
17 0 1

Im trying to hide some specific pages from store search with the followoig code
 
I created a metafield for the page. It wont let me create the seo.hidden metafield (is that just for products?) so I created this one that can just be set to 1 and we can check it for a value.

But the page is still appearing in store search. I am using the flex theme.

I placed this code in the <head> </head> section.

  {% if template contains 'page' %}
    {% if page.metafields.custom.hide_page == 1 %}
      <meta name="robots" content="noindex" >
      <script>
        console.log("hidden from search")
      </script>
      {% else %}
      <script>
        console.log("not hidden")
      </script>
    {% endif %}
  {% endif %}
Replies 0 (0)