Forums
Forums / Theme: Spun / Adding search bar to menu
(@paperpixels)
13 years ago
I am trying to add a search bar to the nav_menu, by adding this to the bottom of functions.php however it will not display.
add_filter('wp_nav_menu_items','add_search', 10, 2); function add_search($items, $args) { if( $args->theme_location == 'primary' ) return $items . '<li>'.get_search_form().'</li>'; }
Any ideas on way it seems to ignore this?
(@paulwp)
Theme location must be primary, meaning you have to actually setup the menu to the theme location.
Also the $echo in get_search_form( $echo ) must be false. http://codex.ww.wp.xz.cn/Function_Reference/get_search_form
$echo
get_search_form( $echo )
false
But to be able to use get_search_form( false ) you need this fix which is now still in trunk.
get_search_form( false )
get_search_form() ignores $echo argument if searchform.php exists http://core.trac.ww.wp.xz.cn/ticket/16541
The topic ‘Adding search bar to menu’ is closed to new replies.