Skip to content

Instantly share code, notes, and snippets.

@JohnLauber
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnLauber/93a0e68ea829c828c742 to your computer and use it in GitHub Desktop.
Save JohnLauber/93a0e68ea829c828c742 to your computer and use it in GitHub Desktop.
Filter to add current-menu-item to menu on page load. The class does not get added to pages used as an archive. This is the solution, so you can get your active/hover ability back. You'll need to know the ID of the menu item which you can grab from developer's tools.
/*****
This gets placed in your functions.php file of your theme.
Change the menu-item-# to your specific menu class identifier
***********/
add_filter('nav_menu_css_class', 'special_nav_class', 10, 2);
function special_nav_class($classes, $item) {
if (in_array('menu-item-#', $classes)) {
$classes[] = 'current-menu-item current_page_item';
}
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment