I want my Shop search bar to only search for products and nothing else. As shown in the photo, my search bar searches both products and pages how do i make it only search for products?
To make your Shopify search bar only search for products and not pages, you can make a small code modification in your theme’s code. Here’s how:
-
Go to your Shopify admin dashboard and click on “Online Store” > “Themes” > “Actions” > “Edit Code”. This will take you to the theme’s code editor.
-
In the code editor, open the “theme.liquid” file, which is located under the “Layout” folder.
-
Look for the following code:
<form action="/search" method="get" class="search-bar" role="search"> <input type="search" name="q" value="{{ search.terms }}" placeholder="{{ 'layout.search.placeholder' | t }}"> <button type="submit" class="search-bar__submit"> {% include 'icon-search' %} </button> </form> -
Replace it with the following code:
<form action="/search" method="get" class="search-bar" role="search"> <input type="hidden" name="type" value="product"> <input type="search" name="q" value="{{ search.terms }}" placeholder="{{ 'layout.search.placeholder' | t }}"> <button type="submit" class="search-bar__submit"> {% include 'icon-search' %} </button> </form> -
Save the changes and preview your store to see the updated search bar.
The modification we made in the code adds a hidden input field with the name “type” and value “product”. This tells Shopify to only search for products when the search bar is used, and not pages or any other content type. The user won’t see this input field as it is hidden, and it won’t affect the appearance or functionality of the search bar in any way.
ive been trying to find that code for 10 minutes, i cannot find it on my theme.liquid and when i search for it nothing appears. Are you able to tell me which row it starts? Thank you
Pm me with details and store URL
