Last active
August 29, 2015 14:00
-
-
Save davechu/11010730 to your computer and use it in GitHub Desktop.
One code correction made for an error that appeared in debug mode. Thanks, Thad Bloom!
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
add_filter( 'body_class', 'dc_parent_body_class' ); | |
function dc_parent_body_class( $classes ) { | |
if( is_page() ) { | |
$parents = get_post_ancestors( get_the_ID() ); | |
$id = ($parents) ? $parents[count($parents)-1]: get_the_ID(); | |
if ($id) { | |
$classes[] = 'top-parent-' . $id; | |
} else { | |
$classes[] = 'top-parent-' . get_the_ID(); | |
} | |
} | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment