apply_filters( 'wp_nav_menu_items', string $items, stdClass $args )

Filters the HTML list content for navigation menus.

Description Description

See also See also

Top ↑

Parameters Parameters


(string) The HTML list content for the menu items.


(stdClass) An object containing wp_nav_menu() arguments.

Top ↑

Source Source

File: wp-includes/nav-menu-template.php

View on Trac

Top ↑

Changelog Changelog

Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by LebCit

    Add HTML5 search form to a menu
    Add this code to functions.php. You can completely modify the output, and style the form as you want.
    Please, don’t forget to replace the theme_location !
    For example, if the id of my menu was main-menu, I would write if( $args->theme_location == 'main-menu' )
    Hope this will help.

    function add_search_form($items, $args) {
              if( $args->theme_location == 'menu-1' ){
              $items .= '<li class="menu-item">'
                      . '<form role="search" method="get" class="search-form" action="'.home_url( '/' ).'">'
                      . '<label>'
                      . '<span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>'
                      . '<input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search …', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" title="' . esc_attr_x( 'Search for:', 'label' ) . '" />'
                      . '</label>'
                      . '<input type="submit" class="search-submit" value="'. esc_attr_x('Search', 'submit button') .'" />'
                      . '</form>'
                      . '</li>';
            return $items;
    add_filter('wp_nav_menu_items', 'add_search_form', 10, 2);

You must log in before being able to contribute a note or feedback.