Archived topic
Navigation search feature inside secondary nav
9 replies · Started by Anthony on August 4, 2017
Hi Tom,
I want to keep the fixed option for my primary nav but move the search feature inside the secondary nav.
Browsing through the forum I saw this code to insert a search field inside my secondary menu
add_filter('wp_nav_menu_items','add_search_box', 10, 2);
function add_search_box($items, $args) {
if( $args->theme_location == 'secondary') {
ob_start();
get_search_form();
$searchform = ob_get_contents();
ob_end_clean();
$items .= '<li class="search-item" title="Search"><a href="#"><i class="fa fa-fw fa-search" aria-hidden="true"></i><span class="screen-reader-text">Search</span></a></li>';
}
return $items;
}
It outputs a full search form, but I'd prefer to replicate the exact same behaviour than the default search feature in the primary nav (a search icon that reveals the search field on click).
What is the best way to do it?
Hi there,
Currently it's not possible, but it is a planned feature.
Thought I saw a solution some where, is this possible?
Not currently, but should be in the next version of GP.
Gotcha gotcha. It's surprising that really no such plugin exists for this simple feature. Many themes have it custom built but I haven't seen a simple solution. I'm about to try to fumble through building one. I'll look for it in the next version of GP though!
P.S. When is that coming out? lol.
Likely in a week or two :)
Any news on this front?
Yes! Give this a shot: https://gist.github.com/generatepress/38a3d4d0e3f1be118cac76937e4c92e6
Let me know :)
Works great!
Awesome! :)