Add a .singular class within the body tag

The is_singular() conditional tag check if the user is displaying a single post, a single page or an attachment, which are respectively check with is_single(), is_page() and is_attachment(). With these conditional tags come three usefull classes nested in the body tag: .single, .page or .attachment. But, no .singular classe to rule them all!

So, I put in ♥ Basics a function to fix that:

/**
* Add custom body classes
*/
add_filter( 'body_class', 'basics_body_class' );
if ( ! function_exists( 'basics_body_class' ) ) :
    function basics_body_class($classes) {
        if ( is_singular() )
        $classes[] = 'singular';
        return $classes;
    }
endif;

The result is that instead of using a long selector like .single, .page, .attachment { … } you just have to specify .singular { … }