nav_menu_item_id
Filter HookDescription
Filters the ID attribute applied to a menu item's list item element.Hook Information
File Location |
wp-includes/class-walker-nav-menu.php
View on GitHub
|
Hook Type | Filter |
Line Number | 207 |
Hook Parameters
Type | Name | Description |
---|---|---|
string
|
$menu_item_id
|
The ID attribute applied to the menu item's ` |
WP_Post
|
$menu_item
|
The current menu item. |
stdClass
|
$args
|
An object of wp_nav_menu() arguments. |
int
|
$depth
|
Depth of menu item. Used for padding. |
Usage Examples
Basic Usage
<?php
// Hook into nav_menu_item_id
add_filter('nav_menu_item_id', 'my_custom_filter', 10, 4);
function my_custom_filter($menu_item_id, $menu_item, $args, $depth) {
// Your custom filtering logic here
return $menu_item_id;
}
Source Code Context
wp-includes/class-walker-nav-menu.php:207
- How this hook is used in WordPress core
<?php
202 * @param string $menu_item_id The ID attribute applied to the menu item's `<li>` element.
203 * @param WP_Post $menu_item The current menu item.
204 * @param stdClass $args An object of wp_nav_menu() arguments.
205 * @param int $depth Depth of menu item. Used for padding.
206 */
207 $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $menu_item->ID, $menu_item, $args, $depth );
208
209 $li_atts = array();
210 $li_atts['id'] = ! empty( $id ) ? $id : '';
211 $li_atts['class'] = ! empty( $class_names ) ? $class_names : '';
212
PHP Documentation
<?php
/**
* Filters the ID attribute applied to a menu item's list item element.
*
* @since 3.0.1
* @since 4.1.0 The `$depth` parameter was added.
*
* @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.
*/
Quick Info
- Hook Type: Filter
- Parameters: 4
- File: wp-includes/class-walker-nav-menu.php
Related Hooks
Related hooks will be displayed here in future updates.