Created
August 28, 2014 05:23
-
-
Save kalenjohnson/43ec68088c534ecb3133 to your computer and use it in GitHub Desktop.
Wordpress - Fix custom post type archive and active menu classes
This file contains hidden or 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 | |
// Taken from http://wordpress.org/support/topic/why-does-blog-become-current_page_parent-with-custom-post-type | |
function remove_parent_classes($class) { | |
// check for current page classes, return false if they exist. | |
return ($class == 'active') ? FALSE : TRUE; | |
} | |
add_filter('nav_menu_css_class', function ($classes) { | |
switch (get_post_type()) | |
{ | |
case 'projects': | |
$classes = array_filter($classes, "remove_parent_classes"); | |
// add the current page class to a specific menu item (replace ###). | |
if (in_array('menu-our-projects', $classes)) | |
{ | |
$classes[] = 'active'; | |
} | |
break; | |
} | |
return $classes; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment