Yes, there is, and the hook is nav_menu_link_attributes:
apply_filters( 'nav_menu_link_attributes', array $atts, WP_Post $item, stdClass $args, int $depth )Filters the HTML attributes applied to a menu item’s anchor element.
For example, this adds the nav-link class to the <a> tag only if the theme location ($args->theme_location) is exactly my-location:
add_filter( 'nav_menu_link_attributes', 'my_nav_menu_link_attributes', 10, 3 );
function my_nav_menu_link_attributes( $atts, $item, $args ) {
if ( 'my-location' === $args->theme_location ) {
// Get existing classes, if any.
$class = $atts['class'] ?? '';
// Now add your custom class(es).
$atts['class'] = "$class nav-link";
}
return $atts;
}
Related Posts:
- On which hook should I be calling register_nav_menu(s)?
- Adding custom text in items titles from wp_nav_menu()
- Why is ‘nav_menu_item_args’ filter’s $item argument empty?
- Third level navigation class
- Hook for number of items in Appearance > Menus > CustomPostType > View All [duplicate]
- Filter for Admin Nav Menus Drop Down
- current-menu-item class not working properly
- Trying to add a custom social icon to a Twenty Twenty-One child theme
- Add a counter beside menu item label
- Removing Submenu from Menu
- insert an HTML element if there is a submenu only
- display cart information within li of cart menu item
- How to handle change the appearance of ‘categories’ box on dashboard?
- How to modify menu text in callback function of ‘walker_nav_menu_start_el’ hook
- Get_avatar filter hook not displaying custom avatar image on frontend
- Displaying a Custom Avatar in WP Bootstrap Navwalker Menus in WordPress
- Add button and title on submenu WordPress
- Add data-icon input to WordPress custom menu links
- Registering menu with ‘Automatically add new top-level pages to this menu’ selected
- Whats the difference between current_page_item and current-menu-item
- Menu limit, cannot add new menu items
- Remove Pagination in Appearance -> Menus -> Categories
- wordpress nav menu using twitter bootstrap
- How can I hook into and edit the text of a wp_nav_menu tag?
- What does a walker menu mean?
- Add a logout menu link [duplicate]
- How to open modal window when clicking a WP menu link?
- How to get current page menu item name instead of full menu item list
- change front end menu depending on user login
- Number of items in a menu
- Sub-Pages only of menu items in current branch using a custom menu
- Hide and show menu subpages
- Mobile menu works on local XAMPP, but not on GoDaddy [closed]
- wp_nav_menu and fallback
- list pages only from master parent
- WordPress cache a menu with Transient API
- Counting top level items in a custom menu walker
- How to display the title for each menu item in a span attribute
- Limit top level menu items on wp_nav_menu
- Wp menu add page link as custom empty link
- How to change the wordpress navigation bar UL to OL in Twenty_Twelve similer theme
- how do I add “home” menu item conditionally to custom menus?
- How to add div to top menu item
- wp_nav_menu including Skype URL
- Why is my menu not ordered properly?
- How to add class to and childs of sidebar widget – WordPress
- header menu structure: cannot add additional menu items without alignment issues
- My menu bar dissapeared with autooptimize [closed]
- Menu in left side don’t appears with dropdown
- WP custom nav menu problem
- Show WordPress Menu On External Site
- Using _s theme, menu changes do not affect header menu
- Change class-name on “current_ancestor” in wp_nav_menu
- Add child pages to submenu automatically
- Menu Arrow for Child Element
- Having trouble adding CSS class through menu to link
- Mobile screen does not display Primary navbar…just a three line icon [closed]
- How do I enable “metaboxes” by default in menu editor?
- The cart, checkout, and shop links not getting removed
- How to pass menu slug as a variable to wp_nav_menu?
- New Menu Item Type Meta Box
- Using Different wp_nav_menu theme_location based on page id (or a parent id)
- Display Menu Navigation Label
- Menu is not displaying on the site navigation [closed]
- Does this function wp_get_nav_menu_object check if a nav menu exists or is supported?
- Updated WordPress, now Navigation is Messed Up
- wp_nav_menu removing containing UL with ‘items_wrap’ => ‘%3$s’ not working
- How to show only current item children using wp_nav_menu?
- Copied site has wrong menu URL behaviour
- Removing wp admin menu item on top bar of admin backend
- Nav_walker add id to dropdown ul
- Navbar is hidden behind carousel when using wp-boostrap-navwalker
- WordPress nav-menus not finding page
- Active Current Menu – Adding class to child theme
- WPML CMS Nav and Custom Nav_Walker Undefined Property Notices [closed]
- Add data-track to links in menu
- Is it possible to seperate wordpress menu by different div?
- How to add odd and even classes to all nav links through walker?
- Output sort number in wp menu list item?
- Admin page and admin menu. Permissions plugin
- Check in walker if current page is descendant
- Add a non-dynamic phrase/character after a page title?
- Primery Menu Configuration problem
- how to display wordpress navbar with top menu outside wordpress system
- Active page link not getting class assigned
- Removing menu item doesn’t get removed on edit post
- Menus not showing in the admin menu, after save
- Customize Walker_nav_menu to show posts if item is category
- Add Protocol to Custom Menus
- How can I stop wp_nav_menu from returning extraneous root links?
- How to add posts with thumbnails to my dropdown menu?
- Change menu item order
- Menu System: Custom Links
- Formatting WordPress Menus (without bullets, inline with text)
- Change Menu Order
- Two Homes In Navigation Menu
- child theme font awesome icons not working
- add dynamic ID for wp_nav_menu after and before
- How to organize the header elements, so that it doesn’t come out differentin mobile view
- How to Remove Parent Page menu slug from WordPress Submenus?