Archived topic
Move search function to secondary menu position
5 replies · Started by Rogier on June 13, 2017
Hi Tom,
I'm trying to move the search function to the Secondary Navigation position instead of the Primary Navigation position. Is there a function for this? Notice: The before header hook is not deep enough, because I want it to be part of the menu list.
Or when not possible, the second best solution: How can I load the following code inside the secondary menu list, so the searchform.php can be overwritten in the Child theme with a custom search mark-up?
<li><?php get_search_form(); ?></li>
Thanks in advance!
Hi there,
The easiest way would be to switch the primary and secondary menu since they both have the same options.
So make the menu you want the search icon primary.
Let me know if this makes sense :)
Hi Leo,
Switching the location of the primary and secondary is a clever thought, but this won't give the desired effect, just an mainmenu in the topbar and vice versa.
I'm guessing you don't understand what I mean with my questions?
Hmm both primary and secondary navigation should have the same settings. Maybe Tom explains better in this post: https://generatepress.com/forums/topic/move-navigation-search/
Let me know if that helps.
For anyone else searching for the solution of my earlier question, adding this to functions.php this will do the trick:
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">' . $searchform . '</li>';
}
return $items;
}
Nice! Thanks for sharing that solution! :)