Jump to content

How to add a Search Block to the header?

Recommended Posts

  • 3 months later...
  • Replies 58
  • Views 42.2k
  • Created
  • Last Reply

Top Posters In This Topic

  • 4 months later...

Did this make the search bar on your site the way it is now? When I followed silva's instructions and added your tweak, I get the word SEARCH in my navigation bar instead and when you click on it, it sends you to the search page. www.walaowehh.com

Link to comment
  • 4 months later...
  • 2 weeks later...
  • 1 month later...
  • 3 years later...

If anyone is interested in getting this to work on the Galapagos template (and any other template if adjustments are made):

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
  /* The code here replaces the search link in the navigation bar (which is required) */
  /* with the search block which was placed initially in the footer (also required) */
  $(".nav-container > ul.nav-list > li:nth-last-child(1) a").replaceWith($(".search-block"));
</script>

This should be injected at Settings > Advanced > Code Injection > Footer (it needs to run after the Search Block you placed in the footer has been created or else it will not work).

If you use another template that doesn't allow search blocks in the header, this should still work, you simply need to inspect the code on your actual webpage (right click > inspect) and search for the class naming conventions your template uses for its <nav> tag and make the necessary changes to the code above.  The Galapagos class naming for the navigation bar is .nav-container which has an unordered list (ul) with class name of nav-list which contains list items (li) so you would change those names (add/remove if needed) accordingly to what you find.

Link to comment

For the Marquee template this is the naming convention that works currently:

$("#desktopNav > .main-nav > .nav-wrapper > ul.cf > li:nth-last-child(1) a").replaceWith($(".search-block"));

$("#desktopNav > .main-nav > .nav-wrapper > ul.cf > li:nth-last-child(1) a").replaceWith($(".search-block"));

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.