Add custom data-attribute to Wordpress navigation menu -
i've seen similar questions here on stackoverflow, mine bit different..
i need able add custom data attribute wordpress menu. problem i've got solutions found, following, example:
add_filter( 'nav_menu_link_attributes', 'my_nav_menu_attribs', 10, 3 ); function my_nav_menu_attribs( $atts, $item, $args ) { // id of target menu item $menu_target = 365; // inspect $item if ($item->id == $menu_target) { $atts['data-reveal-id'] = 'mymodal'; } return $atts; }
allows add same attribute menu items. need, way add same data attribute, different values on each element on list.
this pretty need achive:
<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 need use plugin here: https://github.com/alvarotrigo/fullpage.js#fullpagejs
any advice?
thanks
i guess solution extend navigation items. made before add icons menu items.
take on here - instead of subheadline cann name field "anchortarget" (or else) , call in menu... http://www.wpexplorer.com/adding-custom-attributes-to-wordpress-menus/
if need further hints, should google "wordpress + menu + custom field".
hope helps you. best
Comments
Post a Comment