Extend walker – navigation, adding data attribute to a tag
This is how I added data attribute to my menu It simply adds data-title=”menu-title” to each link on my main nav, change it to adapt to your need. You don’t actually need to use Nav Walker to add this add_filter( ‘nav_menu_link_attributes’, ‘cfw_add_data_atts_to_nav’, 10, 4 ); function cfw_add_data_atts_to_nav( $atts, $item, $args ) { $atts[‘data-title’] = $item->post_title; … Read more