Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davechu/11010730 to your computer and use it in GitHub Desktop.
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!
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