• I have created a CPT for category of projects (the cateogry is in the URL so it prints .com/category-name/project-name/ ). In the custom wp-menu (via the back office) I have links to individual projects but have changed the label so it prints the category name that it belongs to.

    Once a viewer is viewing the project, the selected item from the main menu has a current-menu-item class attached, I want it to to remain whilst the viewer is looking at projects in the same category, however, when they select another project from the same category it disappears. I understand why… but I want them to between projects in the same category and keep the active state in the main menu so it is visually obvious where they are as the two menus are always visible.

    Hope this is clear… Basically I want to know if anyone has a way to append a class to a menu item whilst the viewer is in a certain category? I can of course add a class to each menu item via the back office but then need some help with a script that would essentially say: if page is from: xxx category = append class *current-project-cat* to main menu li (?)…

    If anyone can help here… would be great.

The topic ‘Adding a *current* class to wp-menu item’ is closed to new replies.