You just need the third argument $args
, of which one of it’s properties is theme_location
:
function wpse_218377_nav_menu_css_class( $classes, $item, $args ) {
if ( ! empty( $args->theme_location ) && $args->theme_location === 'custom-menu' ) {
$classes[] = 'footer--menu-item';
}
// ALWAYS return, not from inside the if
return $classes;
}
add_filter( 'nav_menu_css_class' , 'wpse_218377_nav_menu_css_class' , 10, 3 );
Related Posts:
- WordPress nav_menu_css_class theme filter is not being called
- Menu item added in wp_nav_menu_items filter is never highlighted
- How to conditionally add a wp_filter
- Menu items description? Custom Walker for wp_nav_menu()
- 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
- How to remove the Theme Customization Button from the dashboard and themes options page?
- What filters are applied to the_content function?
- How to limit wordpress menu depth in admin panel
- Change admin bar to default:off
- How to modify an image block in Gutenberg WordPress 5?
- Edit srcset and sizes attributes in Gutenberg image, cover and gallery – blocks
- wp_nav_menu sort order?
- How to determine if custom menu is active?
- wp_get_attachment_image_attributes not working for me
- How do I check if a menu exists?
- How to use logout function on custom menu link?
- Display a different theme for not logged-in users
- Any walker causes blank menu?
- How to display wp_nav_menu() conditionally only when not on a 404 page?
- Run shortcode before filters
- How to add menu support to a theme?
- Add class to before_widget for all widgets with a dropdown and a counter
- How to Auto Approve Comments on a Specific 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?
- Get password when user registers and save it sha1 into database
- Select menu on browser resize
- Passing variable in hooks and filter
- Extend walker – navigation, adding data attribute to a tag
- How to add (css) classes to only one wp_nav_menu()?
- Get last modified date for menu link
- Replace Home with image link inside custom header menu
- 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?
- How do I add a post to a menu
- how to change WordPress menu markup/classes
- Setting a Default ‘Theme Location’ When Creating a Menu
- customizing the_password_form filter
- Best practices: Custom theme sidebar menu – hardcode or widget?
- How do I highlight the menu for a child page?
- Custom Nav Walker Displaying Values in Sub Menu
- how to set more than one menus to the same theme location
- Custom Nav Walker to show siblings and children of current branch?
- WordPress Genesis Child Theme Filter divs
- Change file name from wp_generate_attachment_metadata
- CSS won’t style output of wp_nav_menu() correctly
- Create self-populating menu and add extra divs to the menu layout
- Where is definied the theme location for the main menu in a WordPress template?
- how to wrap tag in tag html to wordpress menu conversion
- Second menu not showing
- How to remove class attributes from custom menu markup?
- 2 differen’t menus and it’s using same items in both
- menu behavior is not as expected
- Is there an action for save_menu and/or update_menu?
- Set default screen option for appearance -> menus
- Part of Menu Item Hidden on Header Menu
- wp_nav_menu add something before closing container and after last list item
- Simple way to get two language WP site
- Find the Children of a Page then Echo it as a Bulleted List of Links (menu)
- 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]
- Highlight “Show all” item in wp_list_categories
- WordPress navbar with logo in middle [closed]
- When trying to override plugin’s function by theme, my filter executes two times, I want it to run only a single time
- My Admin bar covers my sticky navbar [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?
- Single-level menu option? Another way?
- 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?
- Should I use add_filter for functions in function.php of the theme?
- Problem with empty class attributes when running a filter on nav_menu_css_class
- Pass variable to hook. Its possible?
- How to append to menu items selectively
- Custom Nav Walker Trouble
- How to set the currently active page in the menu including parents
- Issue on Adding A Class to Bootstrap Navbar Walker Dropdown
- Show woocommerce categories on my theme menu styling
- WordPress taxonomy and archive custom class
- 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?
- Filter categories used with Custom Structure Permalink
- Recommended method for updating/adding menus when adding new theme
- Redirect to another page using contact form 7? [closed]
- Admin: sub menu doesnt display under apperance when activate my themes
- How to wrap all titles generated by Gutenberg “Heading” block with tag
- 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?