nav_menu_link_attributes
Filters the HTML attributes applied to a menu item's anchor element.
Usage
add_filter( 'nav_menu_link_attributes', 'wp_kama_nav_menu_link_attributes_filter', 10, 4 );
/**
* Function for `nav_menu_link_attributes` filter-hook.
*
* @param array $atts The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
* @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.
*
* @return array
*/
function wp_kama_nav_menu_link_attributes_filter( $atts, $menu_item, $args, $depth ){
// filter...
return $atts;
}
- $atts(array)
The HTML attributes applied to the menu item's
<a>element, empty strings are ignored.-
title(string)
Title attribute. -
target(string)
Target attribute. -
rel(string)
The rel attribute. -
href(string)
The href attribute. - aria-current(string)
The aria-current attribute.
-
- $menu_item(WP_Post)
- The current menu item object.
- $args(stdClass)
- An object of wp_nav_menu() arguments.
- $depth(int)
- Depth of menu item. Used for padding.
Changelog
| Since 3.6.0 | Introduced. |
| Since 4.1.0 | The $depth parameter was added. |
Where the hook is called
nav_menu_link_attributes
wp-includes/class-walker-nav-menu.php 297
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $menu_item, $args, $depth );