代码实现:
add_filter('wp_nav_menu_items', 'add_search_form_to_menu', 10, 2);
function add_search_form_to_menu($items, $args) {
// If this isn't the main navbar menu, do nothing
if( !($args->theme_location == 'primary') ) //搜索按钮显示的置,pirmary或者secondary
return $items;
//搜索按钮样式
return $items . '<li class="nav-search hidden-xs">' . '<a role="button" data-toggle="collapse" class="btn btn-default" aria-expanded="false" href="#search">
//此处搜索图标
</a>' . '</li>';
}