Re: How to hide all pages from search results

Solved

How to hide all pages from search results

tesstesting
Explorer
97 0 7

Using debut. I use pages to contain internal information. I don't want customers to see any pages in search results at all. How can I hide all pages from search results?

 

Something like this, but this doesn't work:

{% if item.object_type == 'page' %} 
  {% assign display = false %}
       {% endif %}

 

Accepted Solution (1)
tim
Shopify Partner
3928 399 1444

This is an accepted solution.

There is a number of ways to do it.

If you do not want any  search to find them, it's best to set a seo.hidden metafield .

 

In addition to this, if you do not want this pages to show anything, you may assign a special profile to these pages, which show no page content.

 

Or you may set your site search to not look for pages at all by modifying your search form(s)

Simply add a new field to each form, similar to this:

<input type=hidden name=type value="product,article">

This will hide your pages from internal search only.

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com

View solution in original post

Replies 14 (14)

Dani
Shopify Staff (Retired)
223 43 110

Hi @tesstesting,

 

Dani from Shopify here. Thanks for writing in!

 

I definitely understand why you need to hide this private information. You can do so following our tutorial here. This will prevent the pages you'd like from being searchable while not affecting the public pages. For example, if you have an About Us page that you'd like to keep searchable.

 

For the pages that contain internal information, are you publishing them? If you don't need them to be published you can follow this guide to unpublish them. This way there is no risk of customers being able to see them.

 

How has your 2020 been for your business so far? Since we're now into the new year, have you been able to put into practice anything that you've learned from last year? Or perhaps you had a big win in 2019 that you'd like to try to beat! I'm not sure if you're familiar with our Shopify Academy courses, but we have a new one for Goal Setting that is great for this time of year.

 

Let me know if you have any further questions! I'd be happy to continue helping you.

 

All the best,

 

Dani

To learn more visit the Shopify Help Center or the Community Blog.

tesstesting
Explorer
97 0 7

Hi @Dani @thanks for your reply but i should clarify...I need to hide search results from my own search results on my website.  This tutorial doesn’t help my situation because I’m trying to hide search results from search.liquid not search engines. For example if I have a page called ABC I don’t want customers to see and someone searches ABC into the search bar on my site I don’t want page ABC to appear. Hoping that makes sense.

tim
Shopify Partner
3928 399 1444

This is an accepted solution.

There is a number of ways to do it.

If you do not want any  search to find them, it's best to set a seo.hidden metafield .

 

In addition to this, if you do not want this pages to show anything, you may assign a special profile to these pages, which show no page content.

 

Or you may set your site search to not look for pages at all by modifying your search form(s)

Simply add a new field to each form, similar to this:

<input type=hidden name=type value="product,article">

This will hide your pages from internal search only.

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com
tesstesting
Explorer
97 0 7

@tim 

 

Hey thanks for this help! I looked over the link you sent and I do want to set my site search to not look for pages at all, but I can't figure out where to put your code:

<input type=hidden name=type value="product,article">

FYI I'm using debut!

tim
Shopify Partner
3928 399 1444

Check search-form.liquid snippet and search.liquid  template (as far as I remember only these two), and paste my code somewhere right below the opening <form ...> tag.

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com
tesstesting
Explorer
97 0 7

@tim 

 

Hi Tim, I had to modify your code:

<input type=hidden name=type value="product,article">

because I don't want to hide products or articles, just pages. Is this correct?

<input type=hidden name=type value="page">

I placed it on search-form.liquid and search.liquid but it doesn't change anything.

 

Here's my search-form.liquid with your modified code under the start of the form tag:

{% comment %}
    Renders a search form

    Usage:
    {% include 'search-form' %}
{% endcomment %}
<form action="{{ routes.search_url }}" method="get" class="search-header search" role="search">
  <input type=hidden name=type value="page">
  <input class="search-header__input search__input"
    type="search"
    name="q"
    placeholder="{{ 'general.search.placeholder' | t }}"
    aria-label="{{ 'general.search.placeholder' | t }}">
  <button class="search-header__submit search__submit btn--link site-header__icon" type="submit">
    {% include 'icon-search' %}
    <span class="icon__fallback-text">{{ 'general.search.submit' | t }}</span>
  </button>
</form>

And here's my search.liquid with your modified code under the start of the form tag:

{% paginate search.results by 10 %}

<div class="page-width">
  {% if search.performed == false %}
    <div class="text-center">
      <h1 class="h2">{{ 'general.search.title' | t }}</h1>
  {% else %}
    <div class="section-header text-center">
      <h1 class="h2">
        <span class="visually-hidden">{{ 'general.search.heading' | t: count: search.results_count }}:</span>
        {{ 'general.search.results_with_count' | t: terms: search.terms, count: search.results_count }}
      </h1>
  {% endif %}
      <div class="grid">
        <div class="grid__item medium-up--two-fifths medium-up--push-three-tenths">
          <form action="{{ routes.search_url }}" method="get" role="search" class="search">
            <input type=hidden name=type value="page">
            <div aria-live="polite" class="form-message form-message--error search-result-error-message hide" data-search-error-message>
              <ul id="error-search-form">
                <li>{{ 'general.search.empty_search_message' | t }}</li>
              </ul>
            </div>

            <div class="input-group">
              <input type="search"
                id="SearchInput"
                class="input-group__field search__input"
                name="q"
                value="{{ search.terms | escape }}"
                placeholder="{{ 'general.search.placeholder' | t }}"
                aria-label="{{ 'general.search.placeholder' | t }}"
                >
              <span class="input-group__btn">
                <button id="SearchResultSubmit" class="btn search__submit" type="submit">{{ 'general.search.submit' | t }}</button>
              </span>
            </div>
          </form>
        </div>
      </div>

      {% if search.performed and search.results_count == 0 %}
        <hr class="hr--small hr--invisible" aria-hidden="true" />
        <div class="rte">
          <p>{{ 'general.search.no_results_html' | t: link: routes.root_url }}</p>
        </div>
      {% endif %}
  </div>
</div>


{% if search.performed %}
  {% if search.results_count > 0 %}
    <hr aria-hidden="true" />
  {% endif %}
  <h2 class="visually-hidden">{{ 'general.search.heading' | t: count: search.results_count }}</h2>
  <ul class="page-width list-view-items">
    {% for item in search.results %}
      <li class="list-view-item">
          {% if item.object_type == 'product' %}
            {% include 'product-card-list', product: item %}
          {% else %}
            <div class="product-card product-card--list">
              <a href="{{ item.url }}" class="full-width-link">
                <span class="visually-hidden">{{ item.title }}</span>
              </a>
              <div class="list-view-item__link">
                {% if item.image %}
                  <div class="list-view-item__image-column">
                    <div class="list-view-item__image-wrapper product-card__image-wrapper">
                      <img class="list-view-item__image" src="{{ item.image.src | img_url: '600x600' }}" alt="{{ item.image.alt | escape }}">
                    </div>
                  </div>
                {% endif %}

                <div class="list-view-item__title-column">
                  <div class="list-view-item__title" aria-hidden="true">
                    <span class="product-card__title">{{ item.title }}</span>
                  </div>
                  <div>
                    {% if item.published_at %}{{ item.published_at | date: format: "date" }} &#8212; {% endif %}
                    {{ item.content | strip_html | truncate: 200 }}
                  </div>
                </div>
              </div>
            </div>
          {% endif %}
      </li>
    {% endfor %}
  </ul>

  {%- if paginate.pages > 1 -%}
    {% include 'pagination', paginate: paginate %}
  {%- endif -%}
{% endif %}

{% if item.object_type == 'page' %} 
  {% assign display = false %}
       {% endif %}
  
{% endpaginate %}

 

tim
Shopify Partner
3928 399 1444

No, that's exactly opposite -- you need to keep in that <input> tag those types which you want to be searched -- I gave you the code you should use if you want to search only products and articles.

And as always -- share the (preview) url to your shop -- this will help troubleshooting.

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com
tesstesting
Explorer
97 0 7

@tim 

 

Yes, it appears I put exactly opposite what I was supposed to, thank you for the clarification. It works! I still have one problem though...

 

If customers use a URL to search something like this:

 "https://my-website.com/search?type=pages&q=a" 

or any letter in the alphabet "a"-"z", my internal pages still come up that contain those letters.

Is there any way to prevent customers from using the URL search to access pages?

 

tim
Shopify Partner
3928 399 1444

Well, do you really expect your customers to do this? 🙂

Those must be some cool customers!

 

Then your next best option is to filter search results in  the for loop in section...

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com
tesstesting
Explorer
97 0 7

@tim 

Not my customers in general, no, but a super cool savvy particular customer...possibly :/, and I definitely don't want customers having access to those internal pages (of course those pages don't contain sensitive info...but prefer customers not to be able to see them)...

 

I'm not sure how to go about your suggestion, any ideas?

 

Another workaround I'm wondering is: on my Search results, I show the Image, Title, and Body/Description of products, pages, etc. Can I hide just the title and body/description of the pages *only* so that if said super cool savvy particular customer searches the page, it comes up blank?

tesstesting
Explorer
97 0 7

@tesstesting wrote:

@tim 

Not my customers in general, no, but a super cool savvy particular customer...possibly :/, and I definitely don't want customers having access to those internal pages (of course those pages don't contain sensitive info...but prefer customers not to be able to see them)...

 

I'm not sure how to go about your suggestion, any ideas?

 

Another workaround I'm wondering is: on my Search results, I show the Image, Title, and Body/Description of products, pages, etc. Can I hide just the title and body/description of the pages *only* so that if said super cool savvy particular customer searches the page, it comes up blank?



Just an update for anyone that may be interested...here's how I totally eliminated pages from the search page if users typed the page name into the search box or used an URL.

 

I used Tim's code to eliminate all pages from search results. This made only products and articles come up with the title and description of each item. I only need products in search results to come up. Only minor problem was, if users used URL to search (highly unlikely but best to cover all bases), they could still see the page title and page content if they typed this: mywebsite.com/search?type=pages&q="a" into the url.

 

To eliminate this issue I used this code on my search.liquid:

{% for item in search.results %}
      <li class="list-view-item">
          {% if item.object_type == 'product' %}
            {% include 'product-card-list', product: item %}
          {% else %}
        
        <span class="visually-hidden">

I added span class visually hidden to everything else and closed with:

</span>

Furthermore, if by some chance customers got to the page...I wanted the page to redirect to the contact page.  So I followed Tim's solution code in this thread.

Here's his suggestion from that thread: 

@tim 

You should create an alternate template for Pages and assign it to this page. Since we do not want visitors to see the content, this template can be similar to:

  {% layout none %}
  <script>    window.location.replace("/pages/contact-us");
  </script>

This will redirect to the Contact Us page instead.


 

PS. Here's a thread about how to hide pages with certain tags if thats what you're looking for: "How to omit products or pages tagged with 'wholesale" in search results"

PFPproject
Visitor
2 0 0

Hey Tim - I'm somewhat new to liquid but have experience from way back using HTML and CSS... I have a large number of individual 'profile' pages that I need to assemble but I'm not decided which format (pages or blog articles) might work best. I came across this article as a way to troubleshoot the issue I'm finding with the pages approach...

I have arranged a collapsible content section.  Each row only links to a page, so I made a page with a few links (to be expanded with images and text if I can make this work) that redirect to the individual profile pages. The issue I've found with this approach is that my intermediary pages, that only exist to be loaded within the collapsible section, are showing up on test searches for my basic search terms. 
 - Is this code suitable for hiding those intermediary pages from showing on the search results?

shopifytestsearch.png



My alternate ideas :

A ) Set up the profiles under the Blog option and find a way to hide the date, published by, and then re-phrase the 'Back to Blog' text to read as  "back to ___ " instead
B ) Set up the profiles as Products, but be able to hide/remove the price and buy button from those select 'products'

I feel both A & B would better integrate with the search function without needing to start playing with code... but don't really know how to use the code or where. Can I add in just the above snippet without needing to have the whole page coded, or can I simply use the Liquid code as needed?

Attached is a visual of the collapsible function as I have it now, and then the search results using the blog to host the test profile

 

- please ignore the mess, I'm still playin' with it.

shopifytest.png

- Kona 3

marissa28
Tourist
4 0 8

FOUND A MUCH EASIER SOLUTION NO CODING NEEDED -  - download search and discovery app by shopify - under  settings remove all boxes checked besides "products"  so easy to select what you want showing up under my sites search - i only wanted products not pages. 🙂 

ReddHedd
Tourist
8 0 0

HERO!! 😎