Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi, hope somebody can help with this.
I'm using pages in my Dawn 6.0.2 theme to store snippets of text, size guides etc. to which I then refer from multiple product templates, so I don't need to fill this content for each template separately.
These pages, however, are not to be seen by my shoppers, so I'm trying to find some way how to hide them from storefront search (and ideally from crawlers as well).
I have found multiple tutorials how to do this but I don't seem to be able to replicate them.
First I tried to create a custom metafield for pages with namespace: "seo", key: "hidden", value: "1" and type: "number_integer" (as explained here: https://shopify.dev/api/examples/marketing-seo?shpxid=7edb94e3-317F-4D11-C7BD-90B4D1B1B5FB#hide-a-re...) but that didn't work...
...so I deleted this custom metafield, since this metafield should be there anyway, just not accessible trough the standard UI and edited the value of it to "1" directly trough url (https://STORE_NAME.myshopify.com/admin/bulk?resource_name=Page&edit=metafields.seo.hidden%3Anumber) but that didn't work either - the pages are still showing in storefront search results.
Does anybody know some way, how to do this?
Solved! Go to the solution
This is an accepted solution.
@Cedcommerce this was almost it, thanks a lot, you saved me lot of time 🙂
I only made two changes:
1) When I placed the {% unless %} section as you proposed, it did hide the page I wanted but it "broke" the search results product grid - at places, where the hidden result was supposed to be was empty space, instead of for the other results to fill the empty slot. So I have just moved the code a little (see below).
2) Instead of using page handle I used custom metafield, so I don't need to always edit the code when I want to hide some new page and just change the metafield value.
So if anyone reading this need the same thing, just follow steps below:
Step 1: Go to Admin → Settings → Metafields → Pages → Add definition and create metafield named "hide_from_storefront_search" (or any other name you like) and set content type to Number → Integer, minimum value to "0" and maximum value to "1".
Step 2: Add to your code within the file "main-search-liquid" the red parts below. If you have different theme than Dawn 6.0.2, you might need to be little creative and figure out the differences in code.
{%- 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 %}
<li class="grid__item">
{%- 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' -%}
<div class="card-wrapper underline-links-hover">
<div class="card card--card card--text ratio color-{{ settings.card_color_scheme }}" style="--ratio-percent: 100%;">
<div class="card__content">
<div class="card__information">
<h3 class="card__heading">
<a href="{{ item.url }}" class="full-unstyled-link">
{{ item.title | truncate: 50 | escape }}
</a>
</h3>
</div>
<div class="card__badge {{ settings.badge_position }}">
<span class="badge color-background-1">{{ 'templates.search.page' | t }}</span>
</div>
</div>
</div>
</div>
{%- endcase -%}
</li>
{% endunless -%}
{%- endfor -%}
Step 3: Now just for every page that you want to hide from storefront search change the value of your new metafield to "1".
Thanks everyone for your help! 🙂
Hi, have you try this way?
https://help.shopify.com/en/manual/promoting-marketing/seo/hide-a-page-from-search-engines
@beepzip this only hides the pages from search engines, not from my storefront search, if I understand it correctly.
If you are referring to search results in google or bing,etc that takes time for the pages to be removed as those companies crawlers update their private site indexes.
Or via their webmaster tools to request a recrawl.
The stores internal search can still serve stale content for a little bit, or your browser can also be showing you locally cached content.
Beyond that you'd want to look in the forums for topics on hiding content, hiding products, hiding pages, etc for the different ways that can be used to skip|hide content in store internal search results.
Basically find the search results item loop and do a check on the current items handle, or a metafield, and use a {% continue %} tag to skip it in the loop.
Roughly:
{% if item.metafields.seo.hidden == 1 %}{% continue %}{% endif -%}
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Thanks @PaulNewton, this looks like what I need.
I'm not a programmer though, so even (I think) I have found the loop, I'm not sure where to paste your code exactly.
I tried several places, also with and without {%- else -%}, but every time I either get no change at all or no search results at all - not even products without any value in this metafield.
Can you please advise, where exactly I should paste your code?
Below is part of the code in main-search.liquid - the loop - and by red is marked the code I added.
With code like this I don't get any change in storefront search - all results are displayed regardless the value in the seo.hidden metafield.
{%- for item in search.results -%}
{% if item.metafields.seo.hidden == 1 %}
{% continue %}
{%- else -%}
{% assign lazy_load = false %}
{%- if forloop.index > 2 -%}
{%- assign lazy_load = true -%}
{%- endif -%}
<li class="grid__item">
{%- 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' -%}
<div class="card-wrapper underline-links-hover">
<div class="card card--card card--text ratio color-{{ settings.card_color_scheme }}" style="--ratio-percent: 100%;">
<div class="card__content">
<div class="card__information">
<h3 class="card__heading">
<a href="{{ item.url }}" class="full-unstyled-link">
{{ item.title | truncate: 50 | escape }}
</a>
</h3>
</div>
<div class="card__badge {{ settings.badge_position }}">
<span class="badge color-background-1">{{ 'templates.search.page' | t }}</span>
</div>
</div>
</div>
</div>
{%- endcase -%}
</li>
{% endif -%}
{%- endfor -%}
Hello @VrVa,
To fix this issue you need to follow the below-provided steps:
{% if the template contains 'search' %}
<meta name="robots" content="noindex">
{% endif %}
{% if handle contains 'page-handle-you-want-to-exclude' %}
<meta name="robots" content="noindex">
{% endif %}
Hope this will resolve your issue. Let us know if any more help is needed.
Regards,
CedCommerce
@Cedcommerce this only hides the pages from search engines, not from my storefront search, if I understand it correctly.
Hello @VrVa,
Thank you for reaching out to us.
We can control the rendering page as a search result by editing the theme code. You need to follow the below instructions to fix this issue.
Code:-
{% unless item.handle == "Your page handle" or item.handle == "Your page handle" %}
//other code goes here
{% endunless%}
After adding code:-
Hope it works, let us know if you need any further help with this.
Regards,
CedCommerce
This is an accepted solution.
@Cedcommerce this was almost it, thanks a lot, you saved me lot of time 🙂
I only made two changes:
1) When I placed the {% unless %} section as you proposed, it did hide the page I wanted but it "broke" the search results product grid - at places, where the hidden result was supposed to be was empty space, instead of for the other results to fill the empty slot. So I have just moved the code a little (see below).
2) Instead of using page handle I used custom metafield, so I don't need to always edit the code when I want to hide some new page and just change the metafield value.
So if anyone reading this need the same thing, just follow steps below:
Step 1: Go to Admin → Settings → Metafields → Pages → Add definition and create metafield named "hide_from_storefront_search" (or any other name you like) and set content type to Number → Integer, minimum value to "0" and maximum value to "1".
Step 2: Add to your code within the file "main-search-liquid" the red parts below. If you have different theme than Dawn 6.0.2, you might need to be little creative and figure out the differences in code.
{%- 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 %}
<li class="grid__item">
{%- 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' -%}
<div class="card-wrapper underline-links-hover">
<div class="card card--card card--text ratio color-{{ settings.card_color_scheme }}" style="--ratio-percent: 100%;">
<div class="card__content">
<div class="card__information">
<h3 class="card__heading">
<a href="{{ item.url }}" class="full-unstyled-link">
{{ item.title | truncate: 50 | escape }}
</a>
</h3>
</div>
<div class="card__badge {{ settings.badge_position }}">
<span class="badge color-background-1">{{ 'templates.search.page' | t }}</span>
</div>
</div>
</div>
</div>
{%- endcase -%}
</li>
{% endunless -%}
{%- endfor -%}
Step 3: Now just for every page that you want to hide from storefront search change the value of your new metafield to "1".
Thanks everyone for your help! 🙂
@VrVa We're glad it helped you! keep growing, anything that causes you to hurdle in your growth there's CedCommerce for you.
All the best 🙂
Hi there!
I followed the steps, but for some reason it still shows the pages that I want to be hidden. Could you help?
https://ceramica-living-mock-up.myshopify.com/
password is bohglo
Hey @VrVa thanks for your adjustment and notes....and thanks @Cedcommerce for the original on this, worked for me as well with the Studio theme. I tried a similar question recently and got nowhere. cheers-
I'm glad it helped @rorydean 🙂
Although I recently noticed one tiny BUG within this solution - even though the pages are hidden in the storefront search, the item counters on that page are counting the hidden results as well.
So for example if you have 4 products and one page with "hoodie" in the name and the page is set to be hidden, after searching the term "hoodie" the item counter will display 5 results even though you can only see 4 of them. So just that you now.
Interesting find...I have to say I doubt I would have ever found that. Good to know just the same, but that's not going to matter in my situation. Thanks-
I have this same issue. I like that this solution hides my pages from storefront search, but it will still write "3 results" despite showing 0 results. Does anybody know how to modify the code to reflect the new amount of results?
Hi, this worked for me until I updated my Studio theme to version 11.0.0 from version 10.0.0. Anyone can help with this issue?
We recently spoke with Zopi developers @Zopi about how dropshipping businesses can enha...
By JasonH Oct 23, 2024A big shout out to all of the merchants who participated in our AMA with 2H Media: Holi...
By Jacqui Oct 21, 2024We want to take a moment to celebrate the incredible ways you all engage with the Shopi...
By JasonH Oct 15, 2024