Something like this will help you filter a menu item and add a custom class conditionally. ( Untested )
function add_nav_class( $classes ) {
if ( class_exists( 'current-menu-ancestor' ) || $item->title == 'blog' ) {
$classes[] = 'current-menu-grand-ancestor';
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'add_nav_class', 10, 2 );
Related Posts:
- Mega Menu Walker
- start_lvl Ignored in Custom walker_nav_menu
- Displaying Logged-In User Name in WordPress Menu
- Hide main div if wp_nav_menu is empty
- Check if a menu is empty?
- How to remove a metabox from menu editor page?
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- How to add active class to custom menu using while loop and wp_list_pages
- WordPress menu deletes when trying to add a hook
- Logout and redirect using the WP Menu
- Have CSS Class Added with `is_page()` WP function
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Run a filter when a walker runs
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- Automatically adding new post categories to menu
- Add data attribute to each li in menu
- Unique icons next to each WordPress menu item
- Child page menu in sidebar
- Title Case WordPress Menu Items
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- How to change menu order item
- Add item to top of menu using a filter in functions.php
- Register a menu – Error Header
- Add login hyperlink to secondary navigation menu
- Add value to new attribute inside WordPress menu items
- Get the name of menu item with wp_nav_menu
- How to add aria role and schema markup to custom walker container
- How can I use custom menus with a Bootstrap WordPress theme?
- Nav-Menu not showing up
- Remove submenu item from list
- Dynamic Menu drops pages?
- Menu not styling. New menus functionality giving me a headache
- how to changes mobile menu toggle breakpoint in WordPress
- How to display already created menus via php?
- Providin exception to WordPress wp_nav_menu Custom CSS Classes
- How to put 2 php codes in functions.php without site crashing
- Menu not updating for logged in users after redirect
- Add element after navigation element title don’t works like I expect
- Add parent menu item in sub-menu in custom nav_walker
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Pulling a variable into the wp_nav_menu function
- How I can add div to menu?
- WordPress adding in site URL to header links
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- How to add different menu items on different menus?
- Multiple is_page() in page.php
- Fatal error: Call to undefined function plugin_dir_path()
- Switching wp_get_sites to get_sites
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- One button to change all settings in theme customizer?
- How to show only parents subpages of current page item in vertical menu?
- Add custom image sizes to media uploader
- How can update custom meta for all posts
- Is $hook a global variable in WordPress
- Remove all nav menu classes ( but keep useful ones… )
- wrong php date()?
- Include a php file from functions.php only to homepage
- How do I fetch all comments per post via WP REST API?
- Shortcode content output but not in correct place
- How to restrict page access to logged-in users?
- Handling Body class based on Template
- How to output a PHP file values by shortcode?
- Logged in user ID as post ID
- How to control WordPress image metadata (using Imagick)?
- Custom Walker_Nav_Menu issue with variables on PHP 7.3
- 3 Slashes appear after Apostrophe in custom fields after updating product-site
- Trying to retrieve post meta
- Need help enqueueing webfonts
- Redirect to another page using contact form 7? [closed]
- Error call_user_func_array() expects parameter 1 to be a valid callback when using image_size_names_choose
- How to style one item from main navigation?
- Need php code’s output to display underneath a Divi Module
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- How to make function appear in sentence?
- How to use mysql LIKE with wpdb?
- woocommerce related product title length
- How to modify mobile nav menu text in theme
- Query for user roles
- Use SCSSPHP to compile Theme Customizer Values into .SCSS files ready to compile to CSS
- Displaying Event within two given time frames
- Is there a way to create a “copy post” link?
- Use of antispambot with $curauth->email
- Taxonomy Child Term, Counter is staying on 0
- How to disable sub menu items from being created?
- Access to “My Site” is missing from the admin bar
- How to redirect (301) trashed post to it’s parent taxonomy TERM ARCHIVE instead of 404 page
- How to call WordPress PHP file using external js file
- Using get_theme_mod with checkbox to display content
- Styling admin page rows in order of importance (checkboxes)
- Insert wordpress tags below posts via functions.php
- Pagenav Not appearing on custom Template
- My title is showing after the shortcode
- Load a Header in wordpress
- Trouble figuring out how to get my button to submit comment
- Open WordPress Page from selected option dropdown
- Adding multiple conditional tags in a function?
- Dynamic Email Handler with ‘header (“Location: …’
- Custom plugin doesn’t show in admin menu – when code added, displays an empty page