Extend Shopify headers: Activate inline search bar via JSON toggle and expand with live suggestions

1. Introduction: More flexibility in the header through a toggle

Modern e-commerce stores need flexible, dynamic header features. A frequently requested extension is the option to toggle on or off an inline search bar in the header. Instead of a static button that opens a pop-up, merchant teams can switch between a minimalistic navigation bar and a search that appears directly. In this guide, we'll show you how to integrate a JSON field as a toggle in the theme editor, how to conditionally render the header with Liquid, how to adjust styling using CSS, and how to extend the inline search with live search suggestions. The result is a better user experience and, at the same time, convenient configuration without code changes for merchant teams.

2. Understanding the JSON schema in Shopify themes

Shopify themes define customizable settings via JSON Schema. These settings allow merchant teams to configure their store in the theme editor without touching any code. You can maintain JSON schema globally in config/settings_schema.json or directly within a section file such as sections/header.liquid if the setting only affects that section. Benefits at a glance: User-friendly customization directly in the theme editor. Clear modularity because settings are bundled per section. Dynamic features such as an inline search toggle can be activated in a controlled manner.

3. Add a JSON field as a toggle

To make the header function controllable, create a new JSON field. When activated, this checkbox displays the inline search bar.

A. Global Approach (config/settings_schema.json)

If you want the feature to be available throughout the theme, use the global settings:

JSON:

[
  {
    "name": "Header Settings",
    "settings": [
      {
        "type": "checkbox",
        "id": "enable_in_header_search",
        "label": "Enable In-Header Search",
        "default": false
      }
    ]
  }
]

This snippet creates the “Enable In-Header Search” checkbox in the theme editor. When activated, settings.enable_in_header_search is true.

B. section-specific approach (sections/header.liquid)

If the feature should only affect the header, define the scheme directly in the section:

Liquid:

{% schema %}
{
  "name": "Header",
  "settings": [
    {
      "type": "checkbox",
      "id": "enable_in_header_search",
      "label": "Enable In-Header Search",
      "default": false
    }
  ]
}
{% endschema %}

This keeps the setting closely linked to the header section and keeps your theme modular.

4. Implement toggle in theme code (conditional rendering)

After the toggle exists, you control the output in the header based on its value. Example in sections/header.liquid:

Liquid:

{% if settings.enable_in_header_search %}
  <!-- Inline Search Bar -->
  <form action="/search" method="get" class="header-search">
    <input type="search" name="q" placeholder="Search..." aria-label="Search" id="header-search-input">
  </form>
{% else %}
  <!-- Default Search Button -->
  <button id="search-btn">Search</button>
{% endif %}

If settings.enable_in_header_search is true, the inline search form is shown, otherwise the standard button. In this way, the header dynamically adapts to the configuration in the theme editor.

5. Customize appearance and behavior (CSS & JS)

For a consistent integration, you usually need a few styles and possibly minor JavaScript adjustments.

A. CSS adjustments

CSS:

.header-search {
  display: flex;
  align-items: center;
}

.header-search input[type="search"] {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  width: 200px;
}

Adjust spacing, colors, and widths to your design system. Pay attention to focus states and sufficient contrasts for accessibility.

B. JavaScript considerations

If your theme is already using JS for the previous search (e.g. pop-up), unpair event listeners or only bind them when the inline search bar is active. An easy way is to check whether the inline element exists before binding.

6. Implement live search suggestions (auto suggestions)

Real-time search suggestions are a big advantage in UX. As users type, relevant hits appear. This is how you build up the feature.

6.1 Pick up inputs

JavaScript:

document.getElementById('header-search-input').addEventListener('input', function() {
  const query = this.value;
  if (query.length > 0) {
    fetchSearchResults(query);
  } else {
    clearSearchSuggestions();
  }
});

The listener responds to input and triggers the loading of suggestions.

6.2 Retrieve search results

JavaScript:

function fetchSearchResults(query) {
  fetch(`/search/suggest.json?q=${encodeURIComponent(query)}`)
    .then(response => response.json())
    .then(data => {
      displaySearchSuggestions(data.results);
    })
    .catch(error => {
      console.error('Error fetching search suggestions:', error);
    });
}

The request fetches suggestions asynchronously. Depending on the theme, app, or store setup, the endpoint may vary. Check whether your theme comes with an existing suggest endpoint or whether you should use your own endpoint (e.g. via Search & Discovery or an app).

6.3 Present suggestions

Add a container for suggestions in the header:

HMTL:

<div id="search-suggestions" class="search-suggestions"></div>

And render the items:

function displaySearchSuggestions(results) {
  const suggestionsContainer = document.getElementById('search-suggestions');
  suggestionsContainer.innerHTML = ''; // Clear previous suggestions
  
  results.forEach(item => {
    const suggestionItem = document.createElement('div');
    suggestionItem.className = 'suggestion-item';
    suggestionItem.textContent = item.title; // Adjust according to your data structure
    suggestionsContainer.appendChild(suggestionItem);
  });
}

function clearSearchSuggestions() {
  document.getElementById('search-suggestions').innerHTML = '';
}

Look for clickable suggestions, links to the product, and meaningful fallbacks when there aren't any results.

6.4 Refine user experience

  • Debouncing: Reduce request spam by debouncing inputs by 200—300 ms.
  • Styling: Ensure clear separation, hover and focus states, mobile optimization and sufficient touch areas.
  • Accessibility: Consider keyboard navigation (arrow keys, enter, escape) and ARIA roles/live regions for screen readers.

7. Testing and fine-tuning

Systematic checks are crucial before go-live.

  • Theme backup: Create a duplicate version of your theme to test risk-free
  • Theme Editor: Check whether the toggle works as expected and that the inline search is rendered correctly.
  • Cross-browsers and devices: Test on common browsers and viewports, including iOS/Android.
  • Performance: Observe networking and timing, make sure that live suggestions respond quickly and don't block the main interactions.

conclusion

With a JSON toggle in the header, you make your Shopify theme noticeably more flexible and user-friendly. You've seen how to provide the setting in the theme editor, conditionally control the output with Liquid, design using CSS and further improve the user experience with live search suggestions. The combination of JSON Schema and Liquid creates a robust, extensible basis on which merchant teams can quickly switch between layout variants without access to code. Good luck implementing and fine-tuning your header search.

About UNHYDE®

UNHYDE is a web and Shopify agency from Munich with a focus on web development, UX and digital growth. Our mission: high-performance platforms that create measurable customer experiences and business impact. As a recognized Shopify partner, we have successfully launched numerous shops and web platforms worldwide. Write to us at hello@unhyde.me — we help you with high-conversion header extensions, robust search setup, and clean theme implementations.

Mastering CSS animations & transitions — advanced guide for dynamic web design without JavaScript
CSS selectors explained — The complete guide for efficient web design & precise styling
Shopify Horizon Theme: Modular, pixel-perfect design now also for retailers
Customizing Shopify Themes with Liquid, HTML & CSS — The Complete Developer Guide
Debugging in Shopify Themes: How to fix Liquid, CSS & JavaScript errors efficiently
UNHYDE•UNHYDE•UNHYDE•UNHYDE•UNHYDE•UNHYDE•