nav_menu_item_id filter-hookWP 3.0.1

Filters the ID applied to a menu item's list item element.

Usage

add_filter( 'nav_menu_item_id', 'wp_kama_nav_menu_item_id_filter', 10, 4 );

/**
 * Function for `nav_menu_item_id` filter-hook.
 * 
 * @param string   $menu_id   The ID that is applied to the menu item's `<li>` element.
 * @param WP_Post  $menu_item The current menu item.
 * @param stdClass $args      An object of wp_nav_menu() arguments.
 * @param int      $depth     Depth of menu item. Used for padding.
 *
 * @return string
 */
function wp_kama_nav_menu_item_id_filter( $menu_id, $menu_item, $args, $depth ){

	// filter...
	return $menu_id;
}
$menu_id(string)
The ID that is applied to the menu item's <li> element.
$menu_item(WP_Post)
The current menu item.
$args(stdClass)
An object of wp_nav_menu() arguments.
$depth(int)
Depth of menu item. Used for padding.

Changelog

Since 3.0.1 Introduced.
Since 4.1.0 The $depth parameter was added.

Where the hook is called

Walker_Nav_Menu::start_el()
nav_menu_item_id
wp-includes/class-walker-nav-menu.php 172
$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $menu_item->ID, $menu_item, $args, $depth );

Where the hook is used in WordPress

wp-includes/default-filters.php 612
add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 );