How to hide all pages from search results

Solved
Highlighted
Explorer
72 0 4

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 %}

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
223 42 54

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

Dani | Social Care @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Explorer
72 0 4

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.

0 Likes
Highlighted

Success.

Shopify Expert
2684 67 755

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.

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
I am away till Feb-15.
1 Like
Highlighted
Explorer
72 0 4

@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!

0 Likes
Highlighted
Shopify Expert
2684 67 755

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.

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
I am away till Feb-15.
1 Like
Highlighted
Explorer
72 0 4

@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 %}

 

0 Likes
Shopify Expert
2684 67 755

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.

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
I am away till Feb-15.
0 Likes
Highlighted
Explorer
72 0 4

@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?

 

0 Likes
Highlighted
Shopify Expert
2684 67 755

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...

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
I am away till Feb-15.
0 Likes