Skip to content

Instantly share code, notes, and snippets.

@DenisLeblanc
Created September 3, 2014 16:22
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 DenisLeblanc/e687346a7d5595c2f3ab to your computer and use it in GitHub Desktop.
Save DenisLeblanc/e687346a7d5595c2f3ab to your computer and use it in GitHub Desktop.
Add 'current-menu-parent' class to custom post type menu items
<?php
// make sure to add the registered custom post type to the menu 'Title Attribute'
add_filter('nav_menu_css_class', 'current_type_nav_class', 10, 2 );
function current_type_nav_class($classes, $item) {
$post_type = get_post_type();
if ($item->attr_title != '' && $item->attr_title == $post_type) {
array_push($classes, 'current-menu-parent');
};
return $classes;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment