Skip to content

Instantly share code, notes, and snippets.

@jmsmrgn
Last active December 26, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmsmrgn/7159947 to your computer and use it in GitHub Desktop.
Save jmsmrgn/7159947 to your computer and use it in GitHub Desktop.
WordPress - Short page template body classes
function short_page_template_body_classes( $classes ){
if( is_page() ){
$template = get_page_template_slug(); // returns an empty string if it's loading the default template (page.php)
if( $template === '' ){
$classes[] = 'default-page';
} else {
$classes[] = sanitize_html_class( str_replace( '.php', '', $template ) );
}
}
return $classes;
}
add_filter( 'body_class', 'short_page_template_body_classes' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment