WP HOOKS
filtrod 3.6.0

nav_menu_link_attributes

Args 4Plik wp-includes/class-walker-nav-menu.phpDokumentacja WP ↗

Opis

Dodaje atrybuty do linków w menu — np. aria-label, target czy klasy.

Przykład użycia

add_filter( 'nav_menu_link_attributes', ... )php
add_filter( 'nav_menu_link_attributes', 'wpdocs_menu_link_attrs', 10, 4 );

function wpdocs_menu_link_attrs( $atts, $item, $args, $depth ) {
	$atts['aria-label'] = $item->title;
	return $atts;
}

Parametry

ParametrTypOpis
$attsarray{ The HTML attributes applied to the menu item's <code>&lt;a&gt;</code> 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. }
$menu_item\WP_PostThe current menu item object.
$args\stdClassAn object of wp_nav_menu() arguments.
$depthintDepth of menu item. Used for padding.

Wywołanie

Rejestracja callbackaphp
// rejestracja funkcji zwrotnej — podaj liczbę argumentów!
add_filter( 'nav_menu_link_attributes', 'twoja_funkcja', 10, 4 );

function twoja_funkcja($param_1, $param_2, $param_3, $param_4) {
	// Twój kod
}

Popularne w tej kategorii