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;
return $atts;
}
Related Posts:
- how to change WordPress menu markup/classes
- Custom Navigation build using wp_nav_menu and walker
- WordPress menu walker – Get parent item text inside end_lvl function
- Menu items description? Custom Walker for wp_nav_menu()
- wp_nav_menu(), how to change class?
- Add custom classes to anchor in wp_nav_menu
- Add Caret to Menu Items with Sub-Menus in WordPress Theme
- Strict Standards Error bootstrap navwalker
- Any walker causes blank menu?
- How to add menu support to a theme?
- Displaying wp menus by name without using theme locations
- Setting a Default ‘Theme Location’ When Creating a Menu
- Best practices: Custom theme sidebar menu – hardcode or widget?
- Custom Nav Walker to show siblings and children of current branch?
- Create self-populating menu and add extra divs to the menu layout
- which is the best way to customize nav-menu-template.php?
- Create wordpress header with custom logo in between the menu splitting the menu into two equal parts [closed]
- My Admin bar covers my sticky navbar [closed]
- WordPress is adding margins and padding to my custom menu?
- Programmatically (PHP) get the nr. of items in the primary navigation menu
- WordPress empty Nav Menu error
- How to make theme elements customizable in wordpress?
- Primary navigation menu & footer not showing in category / tag page
- Using a page as home, how do I prevent nav from setting both home and page links active?
- Issue on Adding A Class to Bootstrap Navbar Walker Dropdown
- Help with walker for nav
- Child Theme header1.php file not overwriting parent theme’s header1.php file
- how do i develop a global nav and local nav to be wordpress dynamic?
- Remove/Hide a Widget on a Custom Template
- Custom nav menu not showing
- WordPress custom menu can’t show 3. level submenu
- Programatically Created Menu not Editable in Dashboard
- 3 Level Menu Navigation (3rd Level not displaying)
- How can I show a custom WordPress menu anywhere I want on my website?
- Show all menu levels except top level. How to exclude top level of a menu?
- WordPress Menu item > Sub menu Class update
- Need help with adding custom wordpress menu and sub-menu
- How to achieve this navigation style in wordpress navigation
- HTML TO WP Theme : Submenu goes down wp_nav_menu
- Fallback dosen’t work when not using ‘menu’ attribute
- How to add drop symbol to parent nav items which have child
- WordPress 3.9 two menus in same position?
- Horizontal Navigation
- Strict Standards Error bootstrap navwalker
- How to make navigation a list without a plugin? [duplicate]
- Split up wp_nav_menu with custom walker
- How can you develop on a live WordPress installation that is using W3 Total Cache? [closed]
- Customize comment list markup
- Bar separated navigation by extending Walker_Page
- How should I store global information such as a phone number so that it is editable through the CMS?
- Upgrading a custom theme through the Dashboard
- WordPress nav_menu_css_class theme filter is not being called
- Version control for both Vagrant config and themes being developed [closed]
- Add custom text to menu
- 2 differen’t menus and it’s using same items in both
- Use wp_nav_menu to display ALL pages
- Is there an action for save_menu and/or update_menu?
- Third level navigation class
- How to add a submenu toggle button inside all “li” elements that have a submenu?
- add span class and i tag inside wp_nav_menu link anchor tag
- Displaying recent post excerpts on static front page
- Customizer: save setting/control content to post/page
- Using my WordPress menu on another platform
- Customize how a WordPress theme looks like in the Theme Selector
- Widget Option is Missing
- Default Text not showing from customizer
- Get the amount of posts on a given page
- WordPress Template Part in iFrame
- Walker menu not displaying at all
- How to create and populate with few links a menu in child theme functions.php?
- Add login hyperlink to secondary navigation menu
- Second menu has the first menu ID
- wp_nav_menu and its fallback
- How to Add support for sub-menu item description in wordpress?
- Woocommerce Product attribute not imported with wordpress Importer [closed]
- how to hide home nav link in wordpress
- How do I display a greyed out next_post_link when there is no next post
- How would I make a function to dynamically determine if user is logged to change navigation menu text?
- .current_page_ancestor broken in Twenty Eleven
- Custom menu not showing even though it shows as being registered?
- Why is my navigation in my onepage not working?
- What is inside in $item in start_el function in Walker_Nav_Menu class
- Menu is in Reversed order
- Add active class to wp_nav_menu
- how to edit woocommerce checkout page
- How to know and change the machine name of a menu?
- WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
- Walker_Nav_Menu Add Strings and Class Name
- Class .current-menu-item in custom menu Walker
- Problem with multiple menus in theme
- Header links also appearing in the footer
- How to convert that page to a wordpress template? [closed]
- How do I change the tagline input to textarea?
- WordPress theme Modifications not showing up on live server
- how to make a walker to this (in bootstrap, i try but not work)
- can’t add EVENT LISTENER to a element
- Navigation won’t update to show full path to single post
- Custom navigation / menu output (walker?)
- How to set up a development/staging site to make major changes to the theme then update on the live site?
- Custom Menu (only showing direct cildren) ACF not showing