Use following code as jQuery:
jQuery('#nav li').removeClass('current');
jQuery('#nav>li.current-menu-item').addClass('current');
jQuery('.has-children li.current-menu-item').closest('.has-children').addClass('current');
See jsfiddle (current item red color). When you click “Single Blog” menu item your html structure will like my following example and jQuery will remove class active from it and add class it’s parent exactly like what you wanted.
https://jsfiddle.net/dom8188s/
Related Posts:
- Split up wp_nav_menu with custom walker
- Custom Nav walker display current menu item children, or siblings on no children
- Add a custom walker to a menu created in a widget
- Error “Trying to get property of non-object” with Custom Walker for wp_nav_menu
- WordPress Menu Custom Walker Class
- add span class inside wp_nav_menu link anchor tag
- Determine if a navigation item has children
- Custom Nav Walker menu – Display children count
- Using string instead of object class instantiation on the walker argument breaks wp_nav_menu
- Adding attributes to link in wp_nav_menu using custom Walker function
- Walker_Nav_Menu: put custom code between a particular
- Show top-level parent with submenu menu walker
- Adding a class (arrows) to main menu links that have children?
- Custom nav walker with different output depending on depth
- Adding html elements to wp nav menu
- Bar separated navigation by extending Walker_Nav_Menu
- Bar separated navigation by extending Walker_Page
- Output the aria-labelledby parameter for a nav menu child
- Custom Nav Walker sub-menu HTML construct
- Add div to specific sub-menu
- How to add ID and class in nav menu walker?
- wp_nav_menu custom walker – child items
- How to remove trailing tags from wp_nav_menu walker
- How to add parent element’s title to nav menu’s child?
- Custom Walker anchor tag not inheriting attributes
- Indirect modification of overloaded property WP_Post::$classes has no effect
- Check what “type” a menu item is
- How to display dynamic content in start_lvl function
- Getting post content within wp_nav_walker
- How to add a tag to wp_nav_menu in a child theme
- Use wp_nav_menu to display ALL pages
- How to add a submenu toggle button inside all “li” elements that have a submenu?
- Get top items number from wordpress menu
- How to Overwrite/Customize wp-admin/nav-menus.php in WordPress
- Use menu class in walker function
- How do I separate link levels in a custom menu walker?
- Add within the output of
- wp_list_pages() but only show children on the branch you are on
- Walker class conditional based on parent menu item label or custom css class
- Sub Menu does not display using Nav Walker
- Is this format possible with a custom Nav Walker class?
- Put class on instead li
- Get Menu Name inside walker
- WordPress Menu Walker: add #hashes to child page links (only)
- WordPress Walker – Group two items?
- Difference between walker class and basic php
- Where to implement custom walker class?
- custom walker class
- Custom navigation structure with walker class
- How do you add a around the second level of a Menu?
- Page content loading issue using Walker_Nav_Menu
- How to add class to parent a tag with a sub menu
- Walker Class – Check if menu item has description and if so add class to li
- Help with walker for nav
- Dynamic_sidebar inside wp_nav_menu
- How to add attribute in menu code
- How to remove dropdown from wp_nav_menu
- Why is only the first operation run in my loop – except for on the last repeat? [closed]
- How Do I Add Images To Main Navigation Menu
- Walker menu not displaying at all
- How to add a element with walker menu right after begin of the navigation tags?
- WordPress Nav Walker – Top menu link with dropdown link not clickable (dropdown opens)
- Adding a unique ID to each sub-menu
- Displaying Nav Menu
- Add custom class to li element which has children
- Custom menu walker – remove li tag based on class name
- Show Sidebar Menu Subpages When Clicking Parent
- How can I make wp_nav_menu() support tags?
- How to Add support for sub-menu item description in wordpress?
- Adding a tag to wp_nav_menu
- changing the labels inside appearance -> menus for some for the fields
- Walker_Nav_Menu creating too many closing tags?
- Hook or callback when wp_nav_menu() has completed
- Help with WordPress Custom Nav Walker
- Why is my navigation in my onepage not working?
- Is it possible to get_the_post_thumbnail (Featured Image) inside a sprintf function?
- WordPress menu walker – help to add custom class for each submenu
- Need help with Walker_Nav_Menu class
- why are my walker menu is showing like this?
- What is inside in $item in start_el function in Walker_Nav_Menu class
- Does the Default theme of WordPress like 2016, 2017 and 2019 uses Walker_Nav_Menu Class
- Where to place a svg chevron down in my custom walker?
- Add active class to wp_nav_menu
- Output existing wp_nav_menu with a custom walker
- how to split vertical menu into two columns using walker nav menu
- Classes CSS (Optional) – how do I reference this in php?
- Extending Walker_Nav_Menu in wp_nav_menu List of Empty Items
- Custom menu with Walker class – what should the $db_fields be?
- Show post titles within WordPress bootstrap Dropdown menu
- Add parent link to its submenu
- Creating custom Menu for custom theme
- Count Level 1 Childs for Custom Nav Walker WordPress
- How can I edit submenu headings using wp_nav_menu walker?
- Can’t add optional class to menu item when using Walker_Nav_Menu
- Need direction on a seemingly complex menu walker for automatically inserting a parent link li in it’s submenu ul
- Additional class for.sub-menu UL?
- Determine if a navigation item has children
- wp_nav_menu – Collapse with PHP
- custom walker to add iconfont to wp_nav_menu
- Custom navigation / menu output (walker?)