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:
- Adding first / last CSS classes to menus
- 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
- Menu Items Disappearing
- wp_delete_auto_drafts() deletes links in menus
- Check if a menu is empty?
- how to put the logo in the center of other items in the navigation bar
- renaming an admin menu item with decimal array index number
- How can I hook into and edit the text of a wp_nav_menu tag?
- How to remove a metabox from menu editor page?
- 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?
- 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 create different menu’s for not logged in visitors and for logged in members?
- Can we have a php “page” without a WordPress “page”?
- How to add active class to custom menu using while loop and wp_list_pages
- How can I access the “description” of a menu item?
- removing tags from wp_list_pages() using PHP
- How to place login logout link on menu that redirects users back to current page?
- wp_delete_auto_drafts() deletes links in menus
- How can I add a class to a single menu item?
- Replacing the NavWalker dropdown element
- How to add specific menu on a specific page or pages
- Unusable menus and “Illegal widget setting ID: nav_menu_item[]” error
- WordPress menu deletes when trying to add a hook
- Logout and redirect using the WP Menu
- Remove all nav menu classes ( but keep useful ones… )
- Second Navigation inside header
- Creating new menu item
- Programmatically create menu with custom link
- Custom Loop through category menu to include sub categories
- selected menu item
- 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
- wp nav menu: add attributes to menu items [duplicate]
- 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
- How to display conditional-content if wp_nav_menu( $args ) retruns something
- Can’t extend some core classes
- How to create a sub-page of sub-page?
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Vertical Menu for one page only
- Display specific main Sub Nav on Woocommerce product pages
- PHP drop down menu for my get_category child of
- Widget Logic – display on page and all child
- 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
- How to list categories by page id in wordpress
- Adding button to wordpress menu
- Editing existing pre-created menus in PHP
- Two theme locations for two menus, but only one is showing up
- wp_nav_menu doesn’t work in a duplicate server
- How I can add div to menu?
- wp_nav_menu prints children with parent name
- wp nav menu without label
- Contact form field in wordpress menu
- WP Admin Bar – Get current theme name as custom menu title
- Add extra markup to WP menus
- 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
- Using ‘array’ method in wp_nav_menu causes it to disappear
- 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?
- How to get the count for each taxonomy term
- WP_Nav Highlight Parent Issue
- 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
- Submenu opened problem
- if is_home(), change class of menu-item-225 of wp_nav_menu
- Nav Menu Display
- Adding a unique class to wp_nav_menu
- Change order that the menu is generated with wp_list_pages
- I am extending Walker_Nav_Menu: How can I get the number of children elements of the current item?
- How do I modify the with wp_nav_menu()
- Make a permalink to the most recent blog post
- WordPress menu links with images & class selection
- Open WordPress Page from selected option dropdown
- Inserting a shortcode into a genesis menu?
- Remove Unused Menu Locations
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- How to add different menu items on different menus?
- Custom nav with bootstrap dropdown
- Nav menù doesn’t display selected pages
- Show a text in menu
- make my custom theme support polylang plugin
- Can’t assign menu parent id or menu item breaks
- What is considered good practice for registering menu locations?
- How to Customize the Admin Sidebar Menu in WordPress Multisite Network by changing the backend code of the wp-admin code files?