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>') ); ?>

1 Answer 1


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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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