Skip to content

Instantly share code, notes, and snippets.

@DenisLeblanc
Created July 10, 2014 20:57
Show Gist options
  • Save DenisLeblanc/f3f526153e0ce3c3bf7f to your computer and use it in GitHub Desktop.
Save DenisLeblanc/f3f526153e0ce3c3bf7f to your computer and use it in GitHub Desktop.
Add 'current-menu-parent' class to post type menus
<?php
// Add 'current-menu-parent' CLASS TO CUSTOM POST TYPE MENUS
// 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) {
// Get post_type for this post
$post_type = get_query_var('post_type');
// Go to Menus and add a menu class named: {custom-post-type}-menu-item
// This adds a 'current_page_parent' class to the parent menu item
if( in_array( $post_type.'-menu-item', $classes ) )
array_push($classes, 'current_page_parent');
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment