Skip to content

Instantly share code, notes, and snippets.

@hsquareweb
Created July 20, 2012 15:28
Show Gist options
  • Save hsquareweb/3151332 to your computer and use it in GitHub Desktop.
Save hsquareweb/3151332 to your computer and use it in GitHub Desktop.
WP: Body Class
<?php
// ADDING A CLASS TO THE BODY TAG
function page_bodyclass( $classes ){
if( is_singular() ) {
global $post;
$parent = get_page($post->post_parent);
array_push( $classes, "{$post->post_type}-{$post->post_name}" );
array_push( $classes, "{$post->post_type}-parent-{$parent->post_name}" );
}
return $classes;
}
add_filter( 'body_class', 'page_bodyclass' );
?>
<body <?php body_class(); ?>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment