wp_nav_menu_(menu_slug)_itemsfilter-hookWP 3.0.0

Allows you to change the generated HTML of each menu's items individually based on its slug.

Approximately the following content is passed through the filter:

<li id="menu-item-265" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-265">
	<a href="http://wp-test.ru/post-99">Feedback</a>
</li>
<li id="menu-item-266" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-266">
	<a href="http://wp-test.ru/post-98">All articles</a>
</li>
<li id="menu-item-267" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-267">
	<a href="http://wp-test.ru/post-97">Sitemap</a>
</li>

Usage

add_filter( 'wp_nav_menu_(menu_slug)_items', 'wp_kama_nav_menu_slug_items_filter', 10, 2 );

/**
 * Function for `wp_nav_menu_(menu_slug)_items` filter-hook.
 * 
 * @param string   $items The HTML list content for the menu items.
 * @param stdClass $args  An object containing wp_nav_menu() arguments.
 *
 * @return string
 */
function wp_kama_nav_menu_slug_items_filter( $items, $args ){
	// filter...
	return $items;
}
$items(string)
The HTML of the specific menu's items.
$args(stdClass)
The object containing parameters passed to wp_nav_menu().

Examples

#1 Add a search form to the menu

Suppose the menu is named “My Menu”. The filter name will then be:

// Without a transliteration plugin
wp_nav_menu_%d0%bc%d0%be%d1%91-%d0%bc%d0%b5%d0%bd%d1%8e_items

// With a transliteration plugin
wp_nav_menu_moyo-menyu_items

Add a search form to the menu with slug = moyo-menyu:

add_filter( 'wp_nav_menu_moyo-menyu_items', 'change_nav_my_menu_items', 10, 2 );

function change_nav_my_menu_items( $items, $args ) {
	$items .= '<li>' . get_search_form( false ) . '</li>';

	return $items;
}

Changelog

Since 3.0.0 Introduced.

Where the hook is called

wp_nav_menu()
wp_nav_menu_(menu_slug)_items
wp-includes/nav-menu-template.php 283
$items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args );

Where the hook is used in WordPress

Usage not found.