Skip to content

Instantly share code, notes, and snippets.

@benklocek
Created November 12, 2012 22:32
Show Gist options
  • Save benklocek/4062466 to your computer and use it in GitHub Desktop.
Save benklocek/4062466 to your computer and use it in GitHub Desktop.
Wordpress Functions: CSS Selector for Page as parent of custom post type
//current page filter to shop section
function bracia_add_class_to_wp_nav_menu($classes){
switch (get_post_type()){
case 'course':
// we're viewing a custom post type, so remove the 'current_page_xxx and current-menu-item' from all menu items.
$classes = array_filter($classes, "bracia_remove_parent_classes");
// add the current page class to a specific menu item (replace ###).
if (in_array('menu-item-44', $classes)){
$classes[] = 'current_page_parent';
}
break;
// add more cases if necessary and/or a default
}
return $classes;
}
add_filter('nav_menu_css_class', 'bracia_add_class_to_wp_nav_menu');
function bracia_remove_parent_classes($class){
// check for current page classes, return false if they exist. helper function
return ($class == 'current_page_item' || $class == 'current_page_parent' || $class == 'current_page_ancestor' || $class == 'current-menu-item') ? FALSE : TRUE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment