I figured out a way.
I changed the if statement to
if (in_array('current-menu-item', $classes) ||
in_array('current-page-ancestor', $classes)) {
$classes[] = 'active ';
}
Related Posts:
- wp_get_nav_menu_items() not working with slug
- Error “Trying to get property of non-object” with Custom Walker for wp_nav_menu
- Add Class to Specific Link in Custom Menu
- How do I add a search box to the nav menu?
- How to get IDs for objects in menu branch?
- New post notification in wp_nav_menu
- How to move parent li to end of child ul
- wp_nav_menu() loses ‘current-menu-*’ classes on single product page within category
- How is custom menu hierarchy output handled?
- How to fix strange 500 Error after Editing Menu?
- Remove ‘Menus’ from Twenty Sixteen theme Customizer
- Custom nav walker with different output depending on depth
- List parent item with all child item on child pages
- Override custom menu widget
- Placing widget to menu
- container_class doesn’t seem to be working
- Get menu item slug
- Walker_Nav_Menu: Items not nested correctly
- Add class to menu ul with active child
- Loop through Navbar, Output Icons
- Custom Walker anchor tag not inheriting attributes
- Check what “type” a menu item is
- How to display dynamic content in start_lvl function
- Partial refresh of menu in customizer not working?
- Add custom -element to wp_nav_menu
- Disable automatig SVG tag from menu
- next_post_link() on custom menu structure
- Different fields available for different sites when when customising Menu’s
- Custom walker with hashes instead of links (one-page layout)
- Find out if a page has no parent
- wp_nav_menu() showing list in a different Position?
- Can’t include Language switch in Nav Menu
- Using website header, menu and footer on WordPress blog
- Add within the output of
- Add CSS to head depending on nav menu walker
- Can only get one of two custom menus to display
- wp_nav_menu not working [closed]
- two different separate sections on the same site
- Getting the current menu item id from specific menu
- how to disable default menu classes
- How should I build a custom menu walker for this setup?
- Adding an admin menu page showing the link twice – how to solve this?
- Dynamic_sidebar inside wp_nav_menu
- Can I have a different menu for each parent page?
- My Temptation theme is showing two of the same menu at the top. How do I remove the one that the theme comes with? Please help! [closed]
- Combine 2 categories in one Menu item
- Hide menu from homepage
- How to align last 3 menu items to the right – WordPress main menu [closed]
- WordPress Menu Exchange On Tablet’s Orientation
- changing theme folder name breaks menus – twentyeleven
- Submenu in sidebar custom page template
- How to add a second custom menu in my sidebar when theme only supports one?
- add_filter for where statment issue
- How to hide the menu item created by the theme in WordPress admin panel?
- Custom menu walker – remove li tag based on class name
- How to add columns to wordpress menu editor
- how to insert data in li tag of navigation
- Add menu headings to WordPress sub menus
- Customise the custom menu widget
- add_menu_page does not render the expected result
- Custom menu styling
- Getting the WordPress custom menu titles and outputting them in a theme
- Second Level Menu
- Different Menus based on Category Page
- Additional navigation bar in header
- Is there any difference between widgets (used in order to manage menus) and register_nav_menus() in terms of performance?
- current-menu-item not apllying with wp_nav_menu() on ajax
- Custom link with checkbox that adds additional word to checked menu items
- menu not showing on mobile view
- Hide a menu (navigation bar) on all posts
- Adding menu title to custum URL
- Parent Menu Item Requires Two Clicks for Mobile Device
- Is it possible to have submenu outside of menu element? I dont want submenu to be a child of menu
- Full submenu not displaying in wordpress
- Product categories are mixed when creating menu
- Header lists posts instead of showing primary nav menu
- Add a menu item to the logged in users author page?
- Add Class to Custom Menu Widget ul
- Count Level 1 Childs for Custom Nav Walker WordPress
- Iterate through each menu item into a shortcode
- Loading wordpress menu in an external server
- “Static” Child Menu with Accordian
- Need direction on a seemingly complex menu walker for automatically inserting a parent link li in it’s submenu ul
- Display same menu for parent and all its children
- Image menu on responsive WordPress
- Set a different home link in nav menu
- Remove link from Page name in navigation bar
- Prevent Menu Shortcode From Formatting
- Auto Filled Custom Menus for Custom Post Types?
- Setting up menus before making a template live
- Adding Pages to Menus – No Page Hierarchy in Backend [duplicate]
- Is it possible to add a superscript trademark symbol to a menu?
- Creating a Horizontal menu
- I want my homepage navbar to have different styling to the rest of my site, how can I do this?
- Problems with draft website pages
- Sub menu for a (single) page
- WordPress “add to menu” button not working
- Primary menu shortcode name
- Add acf custom fields so sub item in menus
- change breakpoint widths for divi theme tablet view