I’m trying to resolve a problem with anchor (or jump) links in the main wordpress menu.
If I place a number of jump links to the same page within the menu, it highlights all of the jump links to that page, instead of the one clicked. This is an issue when I navigate to the page with a number of jump links via the menu from another page Is there a workaround to this issue?
I know this has something to do with the php inserting the current-menu-item class to highlight a link in the menu based on the URL of one’s page, but is there a way to filter out current-menu-item class based on the # for the anchor links?
Yes, you should be able to filter the classes assigned with the ‘wp_nav_menu_objects’ filter. Examine the passed menu items array structure to determine how to access the assigned classes.
If you’re willing to create or alter a child theme (and not simply do this via plugin), a better approach is to locate the theme’s call to wp_nav_menu() and add or overwrite a walker argument. Your walker will have complete control over the HTML created for all menu items, with the ability to apply quite complex logic to how it is created.