WordPress filter hook · part of WordPress core

nav_menu_item_attributes

A WordPress core filter that 7 plugins also fire themselves, running on 18K+ sites between them.

“Filters the HTML attributes applied to a menu's list item element.”

How to use nav_menu_item_attributes

It's a filter: your callback receives the value and 3 more arguments, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'nav_menu_item_attributes', function( $li_atts, $menu_item, $args, $depth ) {
	// Change $li_atts here.
	return $li_atts;
}, 10, 4 );

Argument names come from Animation Addons for Elementor's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

This hook is fired by WordPress core too. Official reference on developer.wordpress.org →

7 plugins that fire nav_menu_item_attributes

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. Animation Addons for Elementor icon Animation Addons for Elementor10,000+ installs apply_filters( 'nav_menu_item_attributes', $li_atts, $menu_item, $args, $depth ) widgets/nav-menu/walker-nav-menu.php:168
  2. Themify Builder icon Themify Builder6,000+ installs apply_filters( 'nav_menu_item_attributes', $li_attributes, $item, $args, $depth ) themify/megamenu/class-mega-menu.php:109
  3. RS Template Builder For Elementor icon RS Template Builder For Elementor2,000+ installs apply_filters( 'nav_menu_item_attributes', $li_atts, $menu_item, $args, $depth ) includes/helpers/class-nav-walker.php:37
  4. Zyre Elementor Addons icon Zyre Elementor Addons20+ installs apply_filters( 'nav_menu_item_attributes', $li_atts, $menu_item, $args, $depth ) classes/walker-nav-menu.php:108
  5. SiteCraft icon SiteCraft10+ installs apply_filters( 'nav_menu_item_attributes', $li_atts, $menu_item, $args, $depth ) includes/Elementor/Widgets/Nav_Menu/Sc_Menu_Walker.php:172
  6. DesignSuite icon DesignSuiteFewer than 10 installs apply_filters( 'nav_menu_item_attributes', $li_atts, $menu_item, $args, $depth ) includes/Elementor/Widgets/Nav_Menu/Ds_Menu_Walker.php:172
  7. Arshida Toolkit for WooCommerce icon Arshida Toolkit for WooCommerceFewer than 10 installs apply_filters( 'nav_menu_item_attributes', $li_atts, $menu_item, $args, $depth ) src/Menu/MenuWalker.php:155

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.