donnamcmaster
4/6/2017 - 9:57 PM

WordPress: adds the post type and slug to the <body> class, e.g., "page-about"

WordPress: adds the post type and slug to the class, e.g., "page-about"

<?php
/**
 * Adds the post type and slug to the <body> class, e.g., "page-about".
 */

add_filter( 'body_class', function( $classes ) {
    global $post;

    if ( isset( $post ) ) {
    	$classes[]= "{$post->post_type}-{$post->post_name}";
    }
    return $classes;
});