nav_menu_item_id
Filters the ID attribute 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_item_id The ID attribute 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_item_id, $menu_item, $args, $depth ){ // filter... return $menu_item_id; }
- $menu_item_id(string)
- The ID attribute 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
nav_menu_item_id
wp-includes/class-walker-nav-menu.php 189
$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 647
add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 );