Using a menu walker add a custom item at the end of the menu’s items

You don’t need a walker in this case. A filter called wp_nav_menu_items is available. It allows you to edit the list items of a menu. Just append your own list item with search field.

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

function add_search_to_nav( $items, $args )
{
    $items .= '<li>SEARCH</li>';
    return $items;
}

Note: if you only want to target a specific menu, a dynamic filter exists:

wp_nav_menu_{$menu->slug}_items

Leave a Comment