I saw some similar questions here in stackoverflow, but mine is a little different.
I need to add a custom data attribute to a Wordpress menu. The problem is that all the solutions that I found, for example, are the following:
add_filter( 'nav_menu_link_attributes', 'my_nav_menu_attribs', 10, 3 ); function my_nav_menu_attribs( $atts, $item, $args ) { // The ID of the target menu item $menu_target = 365; // inspect $item if ($item->ID == $menu_target) { $atts['data-reveal-id'] = 'myModal'; } return $atts; }
allows you to add the same attribute to all menu items. What I need is actually a way to add the same data attribute, but with different values ββfor each item in the list.
This is pretty much what I need to achieve:
<ul id="myMenu"> <li data-menuanchor="firstPage" class="active"><a href="#firstPage">First section</a></li> <li data-menuanchor="secondPage"><a href="#secondPage">Second section</a></li> <li data-menuanchor="thirdPage"><a href="#thirdPage">Third section</a></li> <li data-menuanchor="fourthPage"><a href="#fourthPage">Fourth section</a></li> </ul>
because i need to use this plugin here: https://github.com/alvarotrigo/fullPage.js#fullpagejs
any advice?
thanks
source share