Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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.