In this tutorial I show how Expanding Search Bar can be implemented in Genesis.
We are going to add a mobile-friendly flyout search box in Primary Navigation. Initially only the magnifying glass icon will be shown which when clicked, smoothly opens to its left to show the search box. After typing a search term, users can either hit Enter/Return or click on the search icon to initiate the search. When the search input is open, it can be closed either by clicking anywhere on the page or on the search icon.
Screenshots:
Summary of steps:
- Enqueue necessary JS
- Replace standard Genesis Search Form markup with a custom one using
genesis_search_form
filter - Use
wp_nav_menu_items
filter to add the search form at the end in Primary nav - Add CSS
Step 1
Download source from here (direct link to zip file) and extract it.
Upload fonts
folder to child theme directory and delete codropsicons
directory from the server as it's not needed.
Upload js
folder to child theme directory.
Create a file named expanding-search-init.js in the js
directory having the following:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.
Hi Sridhar – thanks for the great info here – very useful. I’ve got one problem with the implementation and that is that in Firefox the search icon seems to be missing. It seems fine in both Chrome and Safari (although not Safari on the iPhone).
Any ideas on how to fix that?
Staging site URL is: http://bibleleagueca.wpengine.com/
Try moving http://pastie.org/pastes/10259462/text from custom.css into style.css.
Great – thank you. Works perfectly. 🙂
Hi Sridhar,
Question how can I disable on mobile while using our in desktop? Any css to hide it?
Thanks
Hi,
You can use this sample CSS to hide it from specific screen sizes and below:
http://pastie.org/pastes/10301866/text
Whats wrong I did the toutorial,as described? Im running Dynamik Website builder. Site is http://www.realgoodmeals.com/ . Please look and see whats wrong.
Thanks
This tutorial is written with Genesis Sample as the active child theme. You would need to make some adjustments to make it work/look properly in other child themes.
I couldn’t get the icomoon fonts to display, despite adding the @font-face in style.css, so I decided to try using dashicons instead. Only had to change the CSS in two places (apart from color adjustments).
Hi Sridhar,
Worked great for me; thank you. However, client would prefer that the icon/expanding search bar appear in header right widget area only and not in the primary navigation. Can you help?
Thank you!
Jennifer
Hey great!
Made it work in Generate Pro.
One thing though I would like this implementation to do:
When the search box expands it should overlay over the other menu items. Right now, if I have to many items in the primary navigation, the search bar gets pushed down and is visible underneath the menu items.
While I could just change the max-width from 500px to 400px it is much more preferable if the search bar worked regardless of the number of items in the primary navigation. If you can expand this tutorial or write another one where this feature is possible I’d be very grateful.
Thanks.
Best regards
hi sridhar– thanks for the info here.
im bumping into an issue with the placement of the search bar. instead of appearing in the primary nav, i’d like it to appear in the utility bar that i created using this tutorial: https://sridharkatakam.com/utility-bar-in-dynamik/
what do i need to change in the functions above to make that work?
Hi Sri,
I need your help please. I implemented this tutorial here – https://thekitchenbookstore.com/, but the mobile menu disappeared. What do I need to do to make it work again? Thanks!