Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

b-grader

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>
<div style="float: left; width: 200px;">
  <?php get_search_form();?>
</div>

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
add comment
 <nav>
   <?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?>
   <ul>
      <li><?php get_search_form();?></li>
   </ul>
 </nav>

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
add comment
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
add comment

Your Answer

 
discard

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.