Created
July 10, 2014 20:57
-
-
Save DenisLeblanc/f3f526153e0ce3c3bf7f to your computer and use it in GitHub Desktop.
Add 'current-menu-parent' class to post type menus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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