Last active
December 26, 2015 13:39
-
-
Save jmsmrgn/7159947 to your computer and use it in GitHub Desktop.
WordPress - Short page template body classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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