Add page slug to body-tag's CSS class
if( !function_exists('add_slug_to_body_class') ) {
function add_slug_to_body_class( $classes ) {
global $post;
if( is_home() ) {
$key = array_search( 'blog', $classes );
if($key > -1) {
unset( $classes[$key] );
};
} elseif( is_page() ) {
$classes[] = sanitize_html_class( $post->post_name );
} elseif(is_singular()) {
$classes[] = sanitize_html_class( $post->post_name );
};
return $classes;
}
}
add_filter('body_class', 'add_slug_to_body_class');
Written by Markus Schober
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#