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
Related Posts:
- Dynamically exclude menu items from wp_nav_menu
- Add custom menu item using wp_nav_menu_items filter
- Does Extending Multiple Nav_Menu_Walkers Allow Nested Menus?
- wp_nav_menu remove class and id from li
- Custom search filter causes menu and query_posts problems
- Unregister Nav Menu from Child-Theme
- Add separator to admin submenu
- On which hook should I be calling register_nav_menu(s)?
- Allow html tags in WordPress Custom Menus Description Field
- Using filters to change href of nav menu page link
- Menu is not visible in appearance
- How to apply a class to the second word in menu list item?
- One site, 2 distinct sections: two different top nav menus?
- WordPress nav_menu_link_attributes Not Working
- Make Theme automatically choose default nav menu
- Is it possible to add a filter for the output of nav-menu items in admin?
- if role is logged in then do something
- Organizing by super-categories (or nested categories)?
- Filter menu item to add classes/attributes?
- Edit html for menu items in default frontend menu
- Nav menu items disappearing (but not immediately)
- wp_nav_menu custom walker – child items
- wp_nav_menu doesn’t generate parent/ancestor classes
- When at / ( or “home”) my menu doesn’t get a current-menu-item class
- How to add parent element’s title to nav menu’s child?
- Why is ‘nav_menu_item_args’ filter’s $item argument empty?
- Add static item to wp_nav_menu
- How to get wordpress nav menu outside of wordpress system?
- Add nav menu CSS class to body
- display only the wp_nav_menu, which has the current-menu-item
- Change HTML structure for custom menu in sidebar
- Using Shortcodes in WP-Menus in WP 3.1 (via nav_menu_objects)?
- Custom Admin Menu Order
- Current menu item
- Removing strip_tags not working on nav_menu_description
- remove everything from wp_nav_menu
- How to add #navbar to all page links?
- How to add wechat (weixin) link to navigation menu?
- Admin only menu/page
- add span to top level links of a wordpress menu called “main”
- How to add custom classes to more than one separate menu’s a link in wordpress?
- Debugging – trying to add search box to menus
- How do I separate link levels in a custom menu walker?
- SlideDeck 2, make back-end visible for admins only
- From a page, is it possible to find entry’s “menu_item_parent”?
- Add active class to top-level menu items when viewing single for that post type
- add_filter on menu items to add a menu item
- how to disable default menu classes
- Insert other menus as submenus of a main menu
- list category posts under its item in menu
- pull non-wp site into content area of wordpress -or- pull wp header into non wp site?
- Help with walker for nav
- Create custom page and add it in nav menu by code
- Using my WordPress menu on another platform
- Remove a menu sub-item
- Redirect to another page using contact form 7? [closed]
- How to add html attributes to the “ul” html tag with “wp_nav_menu” function?
- Using _s theme, menu changes do not affect header menu
- Limit User Iinterface for Admin?
- Make pages visible to only logged in members
- Prevent menu from loading in a page template [duplicate]
- Insert a div before the wp_nav_menu
- How to change menu structure?
- Secondary Navigation Menudisappeared When using wp_nav_menu_items
- remove specific classes from menu items
- Get custom classes in WordPress Navigation Menu
- Replace the slug of parent pages with # [closed]
- wp_nav_menu action/filter help
- add_filter for where statment issue
- Add a counter beside menu item label
- Add custom link on the fly to nav menu
- menu-item class missing on wordpress menu
- How to undo the last changes to a custom menu?
- I can’t add more pages to menu – menu delete pages
- Responsive menu on genesis theme [closed]
- How to open a lightbox form from a navigation menu item
- How to create this kind of sub-menu in new line?
- Hide custom menu when when no menu selected
- if role is logged in then do something
- Possible to append class to nav menu added to widget area?
- Modifying Woocommerce menu based on tags and categories
- Why does WordPress convert absolute URLs to relative URLs for menu items?
- Menu location switcher – example code fails
- Add Featured Image and Title to wp_nav_menu items
- Show thumbnail to category items in wp_nav_menu(), how?
- Add a data attribute to list item element in menu
- Add Class to Custom Menu Widget ul
- Avoid changing menu query with suppress_filters => false
- how to display wordpress navbar with top menu outside wordpress system
- Removing menu item doesn’t get removed on edit post
- Creating and populating custom nav menu (menu-item-position not working)
- custom rearranged menu with excerpt for selected children in sidebar.php
- wp_nav_menu in 3.7 add name class nav navbar-nav
- Add Protocol to Custom Menus
- Menu – custom structure
- custom walker to add iconfont to wp_nav_menu
- How to modify menu text in callback function of ‘walker_nav_menu_start_el’ hook
- After WordPress 4.8 upgrade, wp_nav_menu() string search / replace not working
- Why is WordPress stripping anchor links from mneu item URLs?
- Add button and title on submenu WordPress