Search in WordPress Navigation Menu is probably a wanted feature, many other CMS and Forum Softwares has it by default. Add Search in WordPress Nav Menu easily. Adding a Search in WordPress Navigation Menu was not easy by default as the custom Navigation function was not present in WordPress in older versions.
History of this Search in WordPress Navigation Menu
There are many ways to add Search in WordPress Navigation Menu. The various ways has advantages and disadvantages. This method the standard function of WordPress used to search – get_search_form().
This means, adding Search in WordPress Navigation Menu in this way will probably work for any Theme Framework, if properly modified, which is basically easy.
---
Adding Search in WordPress Navigation Menu
Straightforwardly, coming to the steps needed for adding a Search in WordPress Navigation Menu, you need practically no tool. Better if it is tested on your not so important website. The function and the call is to the functions.php of the current theme. For the default themes and properly arranged premium WordPress Themes, there should be one functions.php and one CSS file, style.css
This is the needed code which should be added in theme’s functions.php file to get Search in WordPress Navigation menu:
1 2 3 4 5 6 | function fb_add_search_box ( $items, $args ){ if( 'primary' === $args -> theme_location ) $items .= '<li>' . get_search_form( FALSE ) . ''; return $items; } add_filter( 'wp_nav_menu_items', 'fb_add_search_box', 10, 2 ); |
This is another piece of code for adding Search in WordPress in nav menu, do not use both.
1 2 3 4 5 6 7 8 9 10 11 12 | add_filter('wp_nav_menu_items','add_search_box', 10, 2); function add_search_box($items, $args) { ob_start(); get_search_form(); $searchform = ob_get_contents(); ob_end_clean(); $items .= '<li>' . $searchform . '</li>'; return $items; } |
Adding the code will add Search in WordPress Navigation Menu. There are few extra steps.
First, go to to Appearance > Theme Editor and find the functions.php file and Edit it :

Save it. Please note that, I have not invented this way to add Search in WordPress Navigation Menu. Probably a WordPress user on forum wrote this code and later others modified it.
Please note that, adding the code for Search in WordPress Navigation Menu within WordPress Editor can break the Theme. In that case, go to FTP and find the functions.php file and look at the end of the code. Usually bizarre words are added while adding code for Search in WordPress Navigation Menu if the theme is active.
Now, it might happen that, the search is a bit left aligned. You need to adjust the style.css file for customizing Search in WordPress Navigation Menu with CSS.
