Add Page Slug to WordPress Body Class

Sometimes it’s really helpful to have some understandable classes attached to the elements, this will enable you to target entire pages for various different styling techniques, here’s a snippet which will use the Page Slug as a class on the element.

function add_body_class( $classes )
    global $post;
    if ( isset( $post ) ) {
        $classes[] = $post->post_type . '-' . $post->post_name;
    return $classes;
add_filter( 'body_class', 'add_body_class' );