I also used this code to hide the products from the search. Is there any way to add to this to prevent it coming up while typing search and in google? Thanks
Thanks, I think that should work as a way to hide products but not quite what I need. Am I right in saying that would that hide any product the metafield was attached to, not just products of quantity 1 or less?
Thanks for your input! Just to clarify you don’t think its possible to create a global rule that could implement this? It would need to be done manually product by product?
Hi Machalleri, I just wanted to check with this method as it seems like some of my options don’t match up with what you said? I’m not sue how this would work.
Thanks for the suggestion Threed but it didn’t seem to effect the products visibility. This was where I placed the code. If you or anyone else has other suggestions would be grateful to hear them. Thanks
Once we’ve looked at all possible options then would consider bringing someone else in, but would have to be confident they had a solution that was not one we’ve already tried out. Thanks
"When the product’s inventory quantity is 1 or less, the code checks if the seo.hidden metafield is already set to 1. If it is, the code doesn’t update the metafields and just sets the “robots” meta tag to “noindex, nofollow”. If the seo.hidden metafield is not set, the code updates the metafields object to include the seo.hidden metafield set to 1, and then updates the product with the new metafields. After that, the “robots” meta tag is set to “noindex, nofollow”.
Note that this code only updates the seo.hidden metafield if it is not already set to 1. If you want to always update the seo.hidden metafield when the product’s inventory is 1 or less, you can remove the check for seo_hidden == null or seo_hidden == '0'."
Gonna be real, I didn’t even know you could change metafield values like this. Sometimes the code AI gives me doesn’t work at all, sometimes it works great. But it’s worth a try!
But my point is that while we rolled out the fixes on our end ASAP, the manipulated URLs still appeared in search. Removing a page from search once it has been crawled by a search engine isn’t instant-- when they show the page to searchers, it’s because when they previously crawled the page, they didn’t see the instructions for .
So even if the page has now changed to have those instructions for a crawler to not index the page, the search engine doesn’t know that yet, so you have to wait for search engines to re-index your site.
There is a fix to this as well. It isn’t instant, but I got my pages removed from the search within half a day. You can ask the search engine to recrawl your website, where it will then read those instructions, and then remove the pages with in their tag.
For example, with Google Search console:
Log in to Google Search Console
Make sure your website is selected as the property
Click on “URL inspection” in the menu
Enter the URL of the page you would like to be re-indexed (in this case, a product page)
You’ll see something that says “Page changed? REQUEST INDEXING”. Click that.
A pop-up will show, testing if the URL can be re-indexed. It takes a little bit
If successful, you will see “Indexing requested - URL was added to a priority crawl queue. Submitting a page multiple times will not change its queue position or priority.”
Thank you so much for you’re help mate I really appreciate it. I’m a bit of a novice to Shopify and I thought I’d fixed this issue for our client previously but he said the items were still showing.
The other aspect I’m not able to fix was when you type the product in the internal searcher it still comes up as a suggested product. However, the code I added does remove it from the search results.
Which theme are you using? I think the search capability changes from theme to theme. In my theme, there is something called predictive-search.liquid. This is associated with the search bar on my theme, where it will try to predict a result as a person is typing. main-search.liquid seems to control the main search result page. Do you have files like this on your site?
I don’t really know if this will work, but you can try this:
{% for item in search.results %}
{% if item.object_type == 'product' -%}
{% if item.product.inventory_quantity > 1 %}
{%- render 'product-item', product: product, list: show_as_list, grid_classes: grid_classes -%}
{% endif %}
{%- endif -%}
{% endfor %}
And no problem! I started working on Shopify stores with no clue on how things work, cause it was part of my job. Way confusing at first, still confusing for me but less so LOL.
Thanks again for you’re help it is really going to benefit me!
I’m using the Warehouse theme and don’t seem to have a main-search.liquid.
I can see some related files, the code didn’t work for me in the search-template.liquid file but maybe you can see some code in either of these that would be relevant to it…
search.ajax.liquid
{% layout none %}
{%- if search.results_count > 0 -%}
{%- if search.types contains 'product' -%}
{{ 'header.search.products' | t }}
{%- assign clean_terms = search.terms | split: ' AND ' | last | remove_first: '*' -%}
{%- for item in search.results limit: 3 -%}
{{ item.title | highlight: clean_terms }}
{{ item.price | money }}
{%- endfor -%}
{%- if search.results_count > 3 -%}
{%- endif -%}
{%- else -%}
{%- if search.types contains 'article' and search.types contains 'page' -%}
{{ 'header.search.blog_posts_and_pages' | t }}
{%- elsif search.types contains 'article' -%}
{{ 'header.search.blog_posts' | t }}
{%- else -%}
{{ 'header.search.pages' | t }}
{%- endif -%}
{%- for item in search.results | limit: 3 -%}
- {{ item.title }}
{%- endfor -%}
{%- endif -%}
{%- else -%}
{%- assign show_empty_state = false -%}
{%- if settings.search_mode == 'product' -%}
{%- assign show_empty_state = true -%}
{%- elsif search.types contains 'article' or search.types contains 'page' -%}
{%- assign show_empty_state = true -%}
{%- endif -%}
{%- if show_empty_state -%}
{{ 'header.search.no_results' | t }}
{%- endif -%}
{%- endif -%}
search.content.liquid
{%- comment -%}
On the dedicated search results, we show products differently from blog posts/pages. As a consequence, this cause all
kind of issues when doing the pagination. To circumvent this issue, when we enter into the search results, we only show
products, and we do another Ajax request to load the products and blog posts only.
{%- endcomment -%}
{%- layout none -%}
{%- assign filtered_terms = search.terms | replace: '*', '' -%}
{%- if filtered_terms contains ' AND ' -%}
{%- assign filtered_terms = filtered_terms | split: ' AND ' | last -%}
{%- endif -%}
{%- if search.results_count > 0 -%}
{%- for result in search.results limit: 20 -%}
{%- if result.object_type == 'product' -%}
{%- continue -%}
{%- endif -%}
- {{ result.title }}
{%- endfor -%}
{%- endif -%}