I've added this code to my functions.php file:
function wpgood_nav_search( $items, $args ) {
$items .= '<li>' . get_search_form( false ) . '</li>';
return $items;
}
add_filter( 'wp_nav_menu_items','wpgood_nav_search', 10, 2 );
I've found it here: adding search bar to the nav menu in wordpress
The problem: this code adds the search bar to desktop and mobile menus, but I need to add the search bar only to my mobile menu, because the desktop version of my site already has a search widget in the left sidebar.
How can I do this? Please, help me. Thanks!
Initializiation of my menus in functions.php :
// Initialize navigation menus
register_nav_menus(
array(
'primary-menu' => esc_html__( 'Primary Menu', 'bento' ),
'footer-menu' => esc_html__( 'Footer Menu', 'bento' ),
)
);
Thank you so much for your help! Finally I have decided to use my initial code and edit the searchbar's position and style with css, because I am not so good in coding:)