I achieved this with some jQuery:
$("#sidebar ul li").each(function () {
if ($(this).find("a").attr("href") == window.location.href) {
$(this).addClass("current-menu-item");
}
});
(My nav is in a div with the id ‘sidebar’, you will need to change the first selector).
It checks if the href of the links is the same as the current URL, and if so, adds “current-menu-item”. You can then style active links with the .current-menu-style class.
Related Posts:
- Mega Menu Walker
- start_lvl Ignored in Custom walker_nav_menu
- Displaying Logged-In User Name in WordPress Menu
- Menu Items Disappearing
- wp_delete_auto_drafts() deletes links in menus
- Check if a menu is empty?
- How can I hook into and edit the text of a wp_nav_menu tag?
- Walker class: Problems with understanding how walk() method can be called without error
- How to Use the Function is_user_logged_in To Display Different Menus?
- Replacing a specific menu item
- How to show only parents subpages of current page item in vertical menu?
- How can I access the “description” of a menu item?
- How can I add a class to a single menu item?
- Remove all nav menu classes ( but keep useful ones… )
- How can I add a custom class to only nav sub-menu > li > a items in WordPress?
- items_wrap not working
- Style wp_page_menu() items
- Have CSS Class Added with `is_page()` WP function
- Run a filter when a walker runs
- How to display conditional-content if wp_nav_menu( $args ) retruns something
- Multiple WordPress Menus that will only display all pages
- Input type search in Menu
- WP Walker using custom css classes
- Change list item content in menu navigation to add a child element with specific class
- Automatically adding new post categories to menu
- Custom Walker_Nav_Menu issue with variables on PHP 7.3
- Child page menu in sidebar
- Title Case WordPress Menu Items
- Trying to store submenu items to render out after main menu
- How to change menu order item
- Add item to top of menu using a filter in functions.php
- Two menus show up
- Register a menu – Error Header
- How to style one item from main navigation?
- Parsing Menu Items and Blog Posts
- Automatically add images to a menu
- Add value to new attribute inside WordPress menu items
- Menu Items fail to save correctly, cause reset of related page metadata
- Dropdown menu for categories
- Menu Custom Data Attributes
- How to display different submenus?
- Get the name of menu item with wp_nav_menu
- How to modify mobile nav menu text in theme
- Output only links using wp_nav_menu()
- How to add aria role and schema markup to custom walker container
- Nav menu from plugin to theme
- Extend Menu Walker Output
- how to add a div inside wp_page_menu
- How to correctly load a different version of main menu based on the user language in WordPress? Is it a good solution?
- Why in this WordPress theme I can’t see the Main Menu?
- Why can’t I add a custom image in my navigation?
- Remove submenu item from list
- conditional: if is page, and all subpages
- wp nav menu: show submenu below li item
- Dynamic Menu drops pages?
- Remove the Tag from wp_nav_menu
- Styling an “active” link outside of WordPress default menu
- Dynamic menu with custom post types
- Adding an Anchor Link to a wordpress menu using WPBakery Page Builder
- How to make only the valid active page of a multilevel menu active with – “.nav li.current-menu-item a”?
- Replace jQuery with PHP or CSS for Customized WordPress wp_nav_menu
- How to set Nav as a default menu in wordpress
- How to put 2 php codes in functions.php without site crashing
- wp_get_nav_menu_items() with ACF
- How to switch between two primary menus (programatically0
- Redirect User when they click Menu Option
- Used a code to revoke some dashboard menus for my contributors but for some reason it’s revoked me access to the editor [closed]
- Get Child of Child Pages in custom Menu
- How to give custom roles the capability to edit one Menu instead of every Menu
- Primary navigation menu with timed items from custom post type
- How to disable sub menu items from being created?
- Bring Font Awesome icons inside menu A tags
- Difference between “Walker_Nav_menu” and “walker”
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Vertical Menu for one page only
- PHP drop down menu for my get_category child of
- How limit the width of a fixed menu-bar on scroll?
- Pulling a variable into the wp_nav_menu function
- Beyond widget side menu editing, with the php page, custom template
- Editing existing pre-created menus in PHP
- Two theme locations for two menus, but only one is showing up
- wp nav menu without label
- Contact form field in wordpress menu
- How to call a certain object/menubar in a PHP file
- Active class not working on custom menu link using add_menu_page
- Sidebar current menu item for parent
- Remove all nav menu classes except those which begin with certain letters
- How to add a code for lastpostdate after/inside a specific menu link?
- Add the “.current-menu-item” class to tag?
- WordPress adding in site URL to header links
- How to change the menu color
- Can’t remove menu items added by plugin
- Custom Links in Walker Class
- Nav Menu Display
- Adding a unique class to wp_nav_menu
- WordPress menu links with images & class selection
- Open WordPress Page from selected option dropdown
- Remove Unused Menu Locations
- How to add different menu items on different menus?
- Nav menù doesn’t display selected pages