Thanks I tried that but the search box disappeared altogether. I had actually tried adding that line before but assumed I must have done it wrong, so just copied and pasted yours, but no luck.
Can you change it to this and give me the additional output it produces?
<?php add_filter('wp_nav_menu_items','add_search_box', 10, 2);
function add_search_box($items, $args) {
var_dump($args); // I want the output of this, as that should help identify what we are doing wrong :)
if ($args->theme_location == 'primary') {
ob_start();
get_search_form();
$searchform = ob_get_contents();
ob_end_clean();
$items .= '<li class="searchbox">' . $searchform . '</li>';
}
return $items;
}?>
Yes, to clarify a bit, and explain why I used main_navigation, the output of $args showed the theme_location as ‘main_navigation’ not ‘primary’, so I just updated primary to be main_navigation