Mostly a search form is a part of the top website header. You can customize the navigation menu and display a search form with it.
Instructions: Add the following code to the functions.php file of your WordPress theme to add search form to specific wp_nav_menu
. If you’ve multiple menus, then replace MENU-NAME
with the name of the menu where you want to add the search form.
add_filter('wp_nav_menu_items', 'add_search_form', 10, 2); function add_search_form($items, $args) { if( $args->theme_location == 'MENU-NAME' ) $items .= '<li class="search"><form role="search" method="get" id="searchform" action="'.home_url( '/' ).'"><input type="text" value="search" name="s" id="s" /><input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" /></form></li>'; return $items; }
You may also enjoy limiting amount of menu items in WordPress.
Hi,
there is a way to avoid close menu after first click in the input? is happening in my case.
thank you
You may want check to see if it is an issue with the theme.
I’m trying to figure out how to order the search form within a nav menu. For example a standard menu with Home About Services Contact Us – could I put the search form after Services and before the Contact Us? Or after Home and before About?