Filter to hook into menu items and add a custom attribute

Actually you can Achieve something similar pretty easy,but also for me was not that easy find an answer. I needed a similar thing for fullpage.js navigation.So i achived like this : i used an alreday existing wordpress menu field that i was not using and i’ve used its value to fullfil my needs

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

  $atts['data-menuanchor'] = $item->attr_title;


return $atts;

}

add_filter( 'nav_menu_link_attributes', 'add_specific_menu_atts', 10, 3 );

inspired by https://codex.wordpress.org/Plugin_API/Filter_Reference/nav_menu_link_attributes