WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

        $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?

share|improve this question


First, you should you this format to add menu location (in your function.php)

add_action('init', 'register_top_menu');

function register_top_menu() {
register_nav_menu('top_menu', __('Top Menu', 'your_text_domain'));
register_nav_menu('bottom_menu', __('Bottom Menu', 'your_text_domain'));

(note: 'your_text_domain' is used for translation..)

Then in the place you want the menu to apear..

<?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?>

so... if you want to add another item seperate to the menu its like this:

<div style="float: left; width: 700px; overflow:hidden;">
<?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?>
<div style="float: left; width: 200px;">
  <?php get_search_form();?>

ofcourese i reccomend using the css at the style.css file
and using classes on the div's themselfs but thats the way i would go about it..

That way you can control the look of each object without them inefiring with each other..

Hope this helps.
Cheers, Sagive.

share|improve this answer
thanks but that ends the menu ul.li which I am using html5 & css to create rounded corners - the rounded corner now rounds out and then the search is presented. – php-b-grader Feb 25 '12 at 4:36
   <?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?>
      <li><?php get_search_form();?></li>

Make nav > ul float left, style the li with your rounded corners and you are done... probably you would need to match the menu ul element margin-right to keep the same distance them. I've done this before and worked great.

share|improve this answer
up vote 0 down vote accepted

Ended up using wp_get_nav_menu_items() and got each item individually and then built the li manually as shown in this example: http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items#Examples

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.