Filter hook 'nav_menu_item_attributes'

in WP Core File wp-includes/class-walker-nav-menu.php at line 228

View Source

nav_menu_item_attributes

Filter Hook
Description
Filters the HTML attributes applied to a menu's list item element. }

Hook Information

File Location wp-includes/class-walker-nav-menu.php View on GitHub
Hook Type Filter
Line Number 228

Hook Parameters

Type Name Description
array $li_atts { The HTML attributes applied to the menu item's `
  • ` element, empty strings are ignored.
  • WP_Post $menu_item The current menu item object.
    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_attributes
    add_filter('nav_menu_item_attributes', 'my_custom_filter', 10, 4);
    
    function my_custom_filter($li_atts, $menu_item, $args, $depth) {
        // Your custom filtering logic here
        return $li_atts;
    }
    

    Source Code Context

    wp-includes/class-walker-nav-menu.php:228 - How this hook is used in WordPress core
    <?php
     223  		 * }
     224  		 * @param WP_Post  $menu_item The current menu item object.
     225  		 * @param stdClass $args      An object of wp_nav_menu() arguments.
     226  		 * @param int      $depth     Depth of menu item. Used for padding.
     227  		 */
     228  		$li_atts       = apply_filters( 'nav_menu_item_attributes', $li_atts, $menu_item, $args, $depth );
     229  		$li_attributes = $this->build_atts( $li_atts );
     230  
     231  		$output .= $indent . '<li' . $li_attributes . '>';
     232  
     233  		/** This filter is documented in wp-includes/post-template.php */
    

    PHP Documentation

    <?php
    /**
    		 * Filters the HTML attributes applied to a menu's list item element.
    		 *
    		 * @since 6.3.0
    		 *
    		 * @param array $li_atts {
    		 *     The HTML attributes applied to the menu item's `<li>` element, empty strings are ignored.
    		 *
    		 *     @type string $class        HTML CSS class attribute.
    		 *     @type string $id           HTML id attribute.
    		 * }
    		 * @param WP_Post  $menu_item The current menu item object.
    		 * @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.