Last active
August 29, 2015 13:56
-
-
Save qstudio/9325333 to your computer and use it in GitHub Desktop.
WP - add post slug and post_type to page body classes
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
<?php | |
// add filter to body_class | |
add_filter( 'body_class', 'q_body_class', 1 ); | |
/* | |
* add extra classes to html body tag | |
*/ | |
function q_body_class( $classes ) { | |
// get $post object ## | |
global $post; | |
if ( $post ) { | |
$classes[] = $post->post_type . '-' . $post->post_name; // posttype-slug ## | |
$classes[] = $post->post_name; // post-slug ## | |
} | |
// return classes ## | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment