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 need to add a search field at the end of a menu in a list item.

I've been looking at walkers but finding it really hard to figure out what is the last item (or even get the total). Also where would i add the code for the custom item.

I've currently got;

class mainNav_walker extends Walker_Nav_Menu
    public function start_el( &$output, $item, $depth, $args )

        $output .= $this->custom_content( $item );
        parent::start_el( &$output, $item, $depth, $args );

    protected function custom_content( $item )
       // add <li>SEARCH FIELD HERE?</li>
share|improve this question
up vote 8 down vote accepted

You don't need a walker in this case. A filter called wp_nav_menu_items is available. It allows you to edit the list items of a menu. Just append your own list item with search field.

add_filter( 'wp_nav_menu_items', 'add_search_to_nav', 10, 2 );

function add_search_to_nav( $items, $args )
    $items .= '<li>SEARCH</li>';
    return $items;

Note: if you only want to target a specific menu, a dynamic filter exists:


share|improve this answer
ace - completely forgot about that method... thanks. – daniel Crabbe May 16 '12 at 10:57
You can check the $args to only add the search to a particular theme (menu) location. – Stephen Harris May 16 '12 at 11:28

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.