In order to automatically add post name to the body class, all you have to do is to copy the following theme and paste it on your theme functions.php file.
1 2 3 4 5 6 7 8 9 | function wpprogrammer_post_name_in_body_class( $classes ){ if( is_singular() ) { global $post; array_push( $classes, "{$post->post_type}-{$post->post_name}" ); } return $classes; } add_filter( 'body_class', 'wpprogrammer_post_name_in_body_class' ); |
Snippet source/Credit: WPProgrammer.com