Filter hook 'nav_menu_link_attributes'

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

View Source

nav_menu_link_attributes

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

Hook Information

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

Hook Parameters

Type Name Description
array $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_link_attributes
add_filter('nav_menu_link_attributes', 'my_custom_filter', 10, 4);

function my_custom_filter($atts, $menu_item, $args, $depth) {
    // Your custom filtering logic here
    return $atts;
}

Source Code Context

wp-includes/class-walker-nav-menu.php:297 - How this hook is used in WordPress core
<?php
 292  		 * }
 293  		 * @param WP_Post  $menu_item The current menu item object.
 294  		 * @param stdClass $args      An object of wp_nav_menu() arguments.
 295  		 * @param int      $depth     Depth of menu item. Used for padding.
 296  		 */
 297  		$atts       = apply_filters( 'nav_menu_link_attributes', $atts, $menu_item, $args, $depth );
 298  		$attributes = $this->build_atts( $atts );
 299  
 300  		$item_output  = $args->before;
 301  		$item_output .= '<a' . $attributes . '>';
 302  		$item_output .= $args->link_before . $title . $args->link_after;

PHP Documentation

<?php
/**
		 * Filters the HTML attributes applied to a menu item's anchor element.
		 *
		 * @since 3.6.0
		 * @since 4.1.0 The `$depth` parameter was added.
		 *
		 * @param array $atts {
		 *     The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
		 *
		 *     @type string $title        Title attribute.
		 *     @type string $target       Target attribute.
		 *     @type string $rel          The rel attribute.
		 *     @type string $href         The href attribute.
		 *     @type string $aria-current The aria-current 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.