Search field in primary_navigation

Searching is now at day 3… I’m trying to learn but php is hurting my brain - how to add this:

<?php get_search_form(); ?>

into the end of this (as the last list element <li>)

<?php if(has_nav_menu('primary_navigation')): wp_nav_menu(array( > 'theme_location' => 'primary_navigation' )); endif; ?>

Thanks in advanced,

This should help: Add custom menu item to the primary nav in wordpress?

Actually you gave me the idea to do this myself on a site I’m tinkering with. I found the most efficient way was to create this filter:

function add_nav_menu_search($args) {
  //ensure it's the nav menu you want to add the search form to
  if($args['theme_location'] == 'primary_navigation') {
    $args['items_wrap'] = $args['items_wrap'].get_search_form();
  }
  return $args;
}
add_filter('wp_nav_menu_args', 'add_nav_menu_search', 20);

Then I just style it using LESS mixins or extend the Bootstrap .navbar-form and either .navbar-right or .navbar-left classes:

.navbar-default .search-form {
	&:extend(.navbar-form, .navbar-right);
}