To only add the custom search box to the main menu you could pass the second parameter provided by the wp_nav_menu_items filter and check if the theme_location is the primary location:
1 2 3 4 5 6 7 8 | function search_box_function( $nav, $args ) { if( $args->theme_location == 'primary' ) return $nav."<li class='menu-header-search'><form action='http://example.com/' id='searchform' method='get'><input type='text' name='s' id='s' placeholder='Search'></form></li>"; return $nav; } add_filter('wp_nav_menu_items','search_box_function', 10, 2); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.