On a website I develop, some pages are in several sub-menus, like so:
home | product category a | products category b
* product a * product c
* product b * product b --> same as in previous menu
Now how do I get WordPress to add current-menu-item
and current-menu-parent
classes to "products category b" and "page b" instead of "product b" in the "product category a".
Currently, it seems that WordPress matches the entries in menu on a first encountered basis. So the entry in that appears first in the menu always takes precedence.
Instead I'd need WordPress to consider what was actually clicked.
So far, the easiest option I have found (no code changes required) is to add a parameter to the url to match a specific menu.
"page b" in "products category b" has its url appended with ?cat=b
. This way, the url is unique to a menu and WP matches it right.
Nevertheless, it's not ideal for SEO and caching. I am therefore still looking for a better solution.