Whenever an attribute is empty WordPress filters decide just not to show the attribute so a simple test for this is the following:
function menu_anchor_attributes ( $atts, $item, $args ) {
$atts['data-menuanchor'] = ( ! empty( $item->attr_title ) ) ? $item->attr_title : 'test';
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'menu_anchor_attributes', 10, 3 );
This way, if a title attribute hasn’t been filled into the back-end it will still display the attribute with a value of test
.
Related Posts:
- Dynamically exclude menu items from wp_nav_menu
- Add custom menu item using wp_nav_menu_items filter
- Custom search filter causes menu and query_posts problems
- Unregister Nav Menu from Child-Theme
- Allow html tags in WordPress Custom Menus Description Field
- Using filters to change href of nav menu page link
- How to apply a class to the second word in menu list item?
- Is it possible to add a filter for the output of nav-menu items in admin?
- if role is logged in then do something
- Filter menu item to add classes/attributes?
- Edit html for menu items in default frontend menu
- Set Item Order with wp_nav_menu_{$menu->slug}_items
- 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 class to active element and its parent in nav menu
- display only the wp_nav_menu, which has the current-menu-item
- Removing strip_tags not working on nav_menu_description
- Third level navigation class
- How to add #navbar to all page links?
- add span to top level links of a wordpress menu called “main”
- Debugging – trying to add search box to menus
- wp_list_pages() but only show children on the branch you are on
- 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
- 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
- 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
- Filter to hook into menu items and add a custom attribute
- 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 Class to Custom Menu Widget ul
- Avoid changing menu query with suppress_filters => false
- Removing menu item doesn’t get removed on edit post
- Add Protocol to Custom Menus
- How to modify menu text in callback function of ‘walker_nav_menu_start_el’ hook
- Why is WordPress stripping anchor links from mneu item URLs?
- Add button and title on submenu WordPress
- wp_nav_menu: show menu only if one exists, otherwise show nothing
- Making breadcrumb with wp_nav_menu
- Renaming a WordPress Admin Menu
- How to add active class on current menu item page?
- Manipulating menu HTML
- Wrap description and sub menu in a wrapper
- Navigation menu with children shown only for current page
- How to get the post name (slug) from the item ID when traversing the navbar?
- how to get nav menu list through menu name in wordpress
- wp_nav_menu – show children of current menu item only?
- $variable (counter) inside wp nav menu
- How to create a Menu based a username
- How to add php to custom link in the nav menu? [closed]
- Remove current class from sub menu items
- How do I render a navigation menu like my theme does?
- WordPress Menu Prepends URL To My Anchors
- Check if menu_item has children or has parent
- pull non-wp site into content area of wordpress -or- pull wp header into non wp site?
- cross-site custom menu
- How to remove the HOME menu item
- display menu as table layout
- How to change the location of the menu
- How can I make a menu link visible only to admins (without plugins)?
- change hover color of specific menu link [closed]
- WordPress classes removed when using custom walker
- Show subpages of a category in a custom menu
- How to add a menu that belongs to parent blog to all child-blogs?
- How to create this kind of sub-menu in new line?
- How to use wp_list_pages on a grandparent page
- Dropdown primary navigation menu not working
- Understanding with this WordPress code
- Link after WordPress
- When created sub-directory, can we create a new navbar?
- Misleading behaviour on Menu & Theme location
- Menu flickering with each refresh on Google Chrome [closed]
- Remove Double Menu in Mobile View and Have one Menu Only
- How i can get current menu id with multiple occurrence
- How to get rid of the bottom line in the navigation menu via CSS file?
- add current-menu-item to multiple custom post types
- Installing compact search in the main menu?
- Next/previous a-like single navigation
- Somehow lost my MENU from my home page- help!
- How to completely remove the top section with the menu?
- How To Conditionally Change Menu In Same Theme Location
- Not even able to Log in [closed]
- how can i get the page_ID in nav li [closed]