call the wordpress navigation label in function.php. (wordpress)

how can i call the value of a navigation label (like: Home, about us, contacs ) and set it as an attribute name?

like this: <a href="#text" class="active"> get this value!!! </a>

and show it here:

Read More
<a SHOW IT HERE ==> data-menuanchor="get this value!!!" <== SHOW IT HERE href="#text"> get this value </a>

i’d like to do it in my functions.php, using something similar to this:

function my_nav_menu_attribs( $atts, $item, $args ){

    $atts['data-menuanchor'] = 'get this value!!!';

}

and if it’s possible make it work even if i add other labels in the future, like this:

<a href="#text" data-menuanchor="first label"> first label </a>
<a href="#text" data-menuanchor="second label"> second label </a>

$atts['data-menuanchor'] = 'label_number';

Related posts