I am using wp_nav_menu() and I want to add the search box as a part of the menu.
I am having trouble figuring it out and was hoping for some assistance:
My code:
<?php
$args = array('theme_location' => 'primary', 'container' => false);
wp_nav_menu( $args );
?>
Now I want to add an additional <li> element to the end or the menu <ul> and all I want in the <li> is the output of:
<?php get_search_form();?>
Can this be done?
functions.php:
add_action('init', 'register_top_menu');
function register_top_menu() {
register_nav_menu('primary', __('Top Menu', 'leeaenergy'));
}
add_filter('wp_nav_menu_items','add_search', 10, 2);
function add_search($items, $args) {
if( $args->theme_location == 'primary' )
return $items . '<li>'.get_search_form().'</li>';
}