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

What is the best way to do this:

<?php wp_nav_menu( array('menu'=>'Primary', 
                         'items_wrap'=>'<ul id="%1$s" class="%2$s">%3$s<li>'.get_search_form().'</li></ul>') ); ?>
share|improve this question
up vote 1 down vote accepted

You can add any item you want to a menu by filtering wp_nav_menu_items. From the tutorial How to Add a Search to Menu, this is how you'd add a search form:

add_filter('wp_nav_menu_items','add_search_box', 10, 2);
function add_search_box($items, $args) {

        $searchform = get_search_form( false );

        $items .= '<li>' . $searchform . '</li>';

    return $items;
share|improve this answer
get_search_form() can return instead of echo by passing false. See codex page – Kailey Lampert Mar 5 '13 at 19:59
Perfect, thank you! – rob-gordon Mar 5 '13 at 20:00
Nice. Thanks for the edit @KaileyLampert. – helgatheviking Mar 6 '13 at 0:22

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.