filtrod 3.6.0
nav_menu_link_attributes
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;
}
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
| Parametr | Typ | Opis |
|---|---|---|
$atts | array | { The HTML attributes applied to the menu item's <code><a></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_Post | The current menu item object. |
$args | \stdClass | An object of wp_nav_menu() arguments. |
$depth | int | Depth 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
}
// 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