Although for the most part you really do not need to be concerned about having so much granularity to specify custom CSS for a self-hosted WordPress site there are occasions when it might be really handy to be able to do so with just the specific current theme being the only one being affected.

With that in mind, the following code will inject into the body class the current theme’s slug so this sort of CSS specificity can be used:

 * Theme Body Classes
 * Returns the parent and child-theme slugs to be used as body classes
 * @param $classes
 * @return array
function wpfa_theme_body_classes( $classes ) {

	/** Extra Points: add Parent Theme "slug" if Child-Theme active */
	if ( is_child_theme() ) {
		$classes[] = sanitize_html_class( wp_get_theme()->parent()->get_stylesheet() );

	$classes[] = sanitize_html_class( get_option( 'stylesheet' ) );

	return $classes;


/** Add classes to the body tag */
add_filter( 'body_class', 'wpfa_theme_body_classes' );

Although you can just drop this into your functions.php theme template file as is (parent or Child-Theme for that matter) remember to appropriately prefix the function to match your theme’s slug.

Obviously there is a lot more you can do with this … I’ll be following up with more ideas in future posts.