Created
July 20, 2012 15:28
-
-
Save hsquareweb/3151332 to your computer and use it in GitHub Desktop.
WP: Body Class
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
<?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