Apologies for both Jan I didn’t realise, thanks for pointing it out!
To Ann:
It seems I jumped the gun with providing the links so I’ll break down how I’d go about solving your issue ?? you need to filter your current menu to include a list item that contains a search bar. This can be done using the filter “wp_nav_menu_items“. This allows you to alter the output for your navigation menus by stating the menu location (called “theme_location” in the arguments), of which your theme currently only supplies the “primary” menu.
So the code required would look as follows:
// Add search to menu
add_filter( 'wp_nav_menu_items', 'add_search_form', 10, 2 );
function add_search_form($items, $args) {
if( $args->theme_location == 'primary' )
$items .= '<li class="search">
<form method="get" class="searchform" action="' . home_url() . '">
<input type="search" value="" placeholder="Search" name="s" id="s">
<input type="submit" id="searchsubmit" value="Search">
</form>
</li>';
return $items;
}
Here we are hooking into the appropriate filter (read more about filters here), checking we are on the “primary” menu and adding some custom HTML to the $items
variable. This custom HTML includes a basic search form with a search input field and a submit button (as used by WordPress). This can be added to your theme’s functions.php file.
This alone will add the required element but it will not automatically adopt the styles of your theme. These will need to be added to your style.css (this file handles how elements on your page look) similar to the following:
/* SEARCH MENU ITEM */
.blog-menu .search {
float: right;
position: relative;
top: 13px;
}
.blog-menu .search::before {
content: '';
}
.blog-menu input[type="search"] {
-webkit-appearance: none;
width: 99%;
padding: 18px 95px 18px 18px;
background: #FFF;
border: 1px solid #DDD;
border-right: none;
font-family: 'Lato', sans-serif;
font-size: 1rem;
border-radius: 3px 0 0 3px;
height: 40px;
}
.blog-menu input[type="submit"] {
-webkit-appearance: none;
position: absolute;
right: 0;
top: 0;
width: 85px;
line-height: 1;
background: #4267b2;
border: 1px solid #4267b2;
color: #FFF;
text-transform: uppercase;
letter-spacing: 1px;
font-size: 0.8rem;
font-family: 'Lato', sans-serif;
border-radius: 0 3px 3px 0;
height: 40px;
}
.mobile-menu .search {
display: none;
}
/* SEARCH MENU ITEM END */
So here we’re using “float” to move the search bar over to the right hand side of our menu bar and positioning it in the middle vertically, overriding the default ‘/’ that is placed before each menu item using “content” and copying over the theme’s styles for the default search bar by adding our css selectors (.blog-menu input[type=”search”] and .blog-menu input[type=”submit”]).
The last bit of code hides out custom search bar when on the mobile menu as one is provided by default in your theme.
All of this can be placed in your theme and will work BUT if you update your theme the changes will be overwritten. I’d strongly suggest creating a child theme (read more here) to avoid this from happening. Child theme’s exist to extend the functionality of your theme, overwriting any behaviour you require but the changes are not lost when your main theme is updated.
I hope this helps ??