Skip to content

Instantly share code, notes, and snippets.

@kalenjohnson
Created August 28, 2014 05:23
Show Gist options
  • Save kalenjohnson/43ec68088c534ecb3133 to your computer and use it in GitHub Desktop.
Save kalenjohnson/43ec68088c534ecb3133 to your computer and use it in GitHub Desktop.
Wordpress - Fix custom post type archive and active menu classes
<?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