Created
May 28, 2013 20:25
-
-
Save brettsnippets/5665825 to your computer and use it in GitHub Desktop.
WordPress: wp_list_pages | Custom Post Type | Class Names
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
function kct_page_css_class( $css_class, $page, $depth, $args, $current_page ) { | |
if ( !isset($args['post_type']) || !is_singular($args['post_type']) ) | |
return $css_class; | |
global $post; | |
$current_page = $post->ID; | |
$_current_page = $post; | |
_get_post_ancestors($_current_page); | |
if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) ) | |
$css_class[] = 'current_page_ancestor'; | |
if ( $page->ID == $current_page ) | |
$css_class[] = 'current_page_item'; | |
elseif ( $_current_page && $page->ID == $_current_page->post_parent ) | |
$css_class[] = 'current_page_parent'; | |
return $css_class; | |
} | |
add_filter( 'page_css_class', 'kct_page_css_class', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment