You can try to alter the $attributes string, since that outputs the attributes in the a tag. The following is untested:
$myClass="some-custom-class";
$myClassAdded = false;
$attributes="";
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
if( $attr == 'class' ){
$value .= ' ' . $myClass;
$myClassAdded = true;
}
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
if( !$myClassAdded ){
$attributes .= ' class="' . $myClass . '"';
}
I also added an extra boolean in case the class attribute is never found in the loop.
Related Posts:
- How to add posts to custom menus?
- wp_nav_menu(), how to change class?
- Display Menu Name using wp_nav_menu
- How can I display a menu on certain pages only?
- Add custom classes to anchor in wp_nav_menu
- Add Caret to Menu Items with Sub-Menus in WordPress Theme
- wp_nav_menu sort order?
- How do I check if a menu exists?
- How to use logout function on custom menu link?
- Any walker causes blank menu?
- How to display wp_nav_menu() conditionally only when not on a 404 page?
- Problem with registering menus – What to do when other solutions aren’t working?
- Add a #hash to the links in my custom menu
- How can i change menu link when page content empty?
- Select menu on browser resize
- How to add (css) classes to only one wp_nav_menu()?
- Get last modified date for menu link
- Displaying wp menus by name without using theme locations
- How to add nofollow to wp_nav_menu
- How to highlight the current page in the nav menu?
- WordPress nav_menu_css_class theme filter is not being called
- Custom Nav Walker Displaying Values in Sub Menu
- CSS won’t style output of wp_nav_menu() correctly
- Create self-populating menu and add extra divs to the menu layout
- how to wrap tag in tag html to wordpress menu conversion
- How to remove class attributes from custom menu markup?
- 2 differen’t menus and it’s using same items in both
- Is there an action for save_menu and/or update_menu?
- Set default screen option for appearance -> menus
- wp_nav_menu add something before closing container and after last list item
- Find the Children of a Page then Echo it as a Bulleted List of Links (menu)
- WordPress navbar with logo in middle [closed]
- WordPress is adding margins and padding to my custom menu?
- wp_post->post_parent object returning 0
- WordPress empty Nav Menu error
- multisite: global menu containing network site links?
- 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?
- How to set the currently active page in the menu including parents
- Where am I doing wrong in my theme menu?
- Custom Navigation build using wp_nav_menu and walker
- Override customizer values on a per-menu base
- Why does has_nav_menu return false when get_registered_nav_menus shows the opposite?
- Recommended method for updating/adding menus when adding new theme
- Child Theme header1.php file not overwriting parent theme’s header1.php file
- Why wp_nav_menu() doesnt show the proper meny when invoked two consecutive times?
- How to develop a menu like wwe.com?
- 3 Level Deep Navigation Menu Not Showing All Levels
- Why are some of my menu items not displaying on my menu?
- How should I use starter content utility to show some default menus?
- How to create and populate with few links a menu in child theme functions.php?
- Second menu has the first menu ID
- How to add menù section to my WordPress template?
- Thesis -style Navigation
- How can i make multilevel menu in wordpress theme with bootstrap
- how do i develop a global nav and local nav to be wordpress dynamic?
- Adding content inside the anchor tags within WordPress main nav
- Why is my container argument not working for wp_nav_menu() [closed]
- How to Emulate Default Navigation Menu Behaviour in a Custom Theme?
- Does wordpress add their own classes into nav menus?
- Custom menu: Link names
- Custom nav menu not showing
- .current_page_ancestor broken in Twenty Eleven
- if (has_custom_menu())?
- Why do sticky posts show in this menu?
- Making a horizontal flyout menu from WordPress category listing
- WordPress custom menu can’t show 3. level submenu
- how to create/register menu items that can be added to menus later
- Why nav_menu_css_class doesn’t work with apply_filters?
- Programatically Created Menu not Editable in Dashboard
- Building a custom menu or use a plugin?
- 3 Level Menu Navigation (3rd Level not displaying)
- Use instead of for wp_nav_menu()
- Pages not displaying as sections on static page
- How can I show a custom WordPress menu anywhere I want on my website?
- Cold Fusion to WordPress
- Menu is in Reversed order
- WordPress Menu item > Sub menu Class update
- Menu names not getting translated
- Nav menus Fast previewing not working with wp_get_nav_menu_items!
- How to know and change the machine name of a menu?
- How to add custom nav_menu_css_class to certain menu only?
- How to add drop symbol to parent nav items which have child
- After theme change the menus have to be manually linked to the corresponding theme location
- How to add custom field option with menu?
- Horizontal Navigation
- What’s the policy for building a theme that doesn’t support widgets/menus?
- Problem with multiple menus in theme
- Main Menu Theme Different Output Print
- Menu item not created on theme activation
- How do I move menu to the bottom in Custom Community theme?
- Header links also appearing in the footer
- Creating Multiple Menus in the Thesis Theme?
- How do I middle-align my header menu items in WordPress [closed]
- Global Navigation menu in diiferrent wordpress setups
- Add wrapper for a specific sub-menu
- 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]
- Why is wp_nav_menu() not removing the container around the nav ?