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]
- wp_nav_menu_items callback not triggered
- When to use is_home() vs is_front_page()?
- How to add posts to custom menus?
- Support Multiple featured images
- What’s the policy for building a theme that doesn’t support widgets/menus?
- Customize Walker_nav_menu to show posts if item is category
- WordPress 3.5 + Foundation 5 not working on IE9
- How Does One Create a Global Variable Repository
- Add the “.current-menu-item” class to tag?
- What hook to use for loading a custom class extension during Theme initialization?
- Problem with multiple menus in theme
- Main Menu Theme Different Output Print
- trying to figure out how to use more that one image upload in the same section in theme customizer
- Menu item not created on theme activation
- Determine if a navigation item has children
- Walker for menus
- Theme Option’s Save Button is not working
- How can I change the title of the Home link in the navigation bar?
- How do I move menu to the bottom in Custom Community theme?
- Header links also appearing in the footer
- custom walker to add iconfont to wp_nav_menu
- How to convert that page to a wordpress template? [closed]
- Not Found when using activity stream as front page with BuddyPress
- Creating Multiple Menus in the Thesis Theme?
- How do I change the tagline input to textarea?
- WordPress theme Modifications not showing up on live server
- Turning WordPress Into full-featured website?
- how to make a walker to this (in bootstrap, i try but not work)
- How do I middle-align my header menu items in WordPress [closed]
- How to highlight current menu bar base on the URL?
- can’t add EVENT LISTENER to a element
- Global Navigation menu in diiferrent wordpress setups
- removing extra mobile menu from the header
- Best practice to create required pages
- Permalinks problem with custom theme
- Navigation won’t update to show full path to single post
- Fatal error: Call to undefined function the_posts_navigation()
- How customizable is a self-hosted WordPress blog compared to a Blogger blog?
- how can i get the page_ID in nav li [closed]
- Custom navigation / menu output (walker?)
- How can i move my product name & price from below thumbnail to be the rollover content in Avada & Woocommerce?
- How to split the site’s layout without damaging this layout? [closed]
- Multiple content areas with Gutenberg – Transparent areas mid content
- Bootstrap 4 mobile menu not working for WordPress Development
- Add wrapper for a specific sub-menu
- How to set up a development/staging site to make major changes to the theme then update on the live site?
- How to automatically set a Template Page Name next to a page in menu screen such as WooCommerce pages, front page, or posts page in wordpress?
- Dynamic nav menu with icons [closed]
- Custom Menu (only showing direct cildren) ACF not showing
- Nav walker bootstrap: Display 3rd level and 4th level in dropdown menu
- Why is wp_nav_menu() not removing the container around the nav ?
- Remove WordPress Menu Classes and ID with Bootstrap Walker
- Custom loop menu is not working
- Disable interactivity for core navigation
- How can I keep a WordPress dropdown menu open when navigating to a child page?