Snippet: Add Search Bar to WP Menu

Add this to function.php to add the search bar to the end of the menu.

add_filter('wp_nav_menu_items','add_search_box_to_menu', 10, 2);

function add_search_box_to_menu( $items, $args ) {
    if( $args->theme_location == 'YUUR_MENU_NAME' )
    return $items.get_search_form();
    return $items;
}

 

Let's make something
awesome together

Get in Touch