1

I am using the following code to add a search box into the navigation menu:

add_filter( 'wp_nav_menu_items','add_search_box', 10, 2 );
function add_search_box( $items, $args ) {
   $items .= '<li class="menu-searchbox">' . get_search_form( false ) . '</li>';
   return $items;
}

It works great, but it adds the search box at the end of the menu as the last <li> item

Is there any way the search box could be added as the first item on the menu?

Vel
  • 9,027
  • 6
  • 34
  • 66
Joe Bloggs
  • 1,410
  • 2
  • 24
  • 53

1 Answers1

1

Try this code

add_filter( 'wp_nav_menu_items','add_search_box', 10, 2 );
function add_search_box( $items, $args ) {
    $searchbox = '<li class="menu-searchbox">' . get_search_form( false ) . '</li>';

    return $searchbox.$items;
}
Vel
  • 9,027
  • 6
  • 34
  • 66