From 15af3fdaa88ee8585d4661390fa30348c4e71872 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Wed, 29 Oct 2014 22:19:08 +0000 Subject: [PATCH] Improve body class for page templates. * Convert slash to dash too. * Add sub-folder name as a separate body class. * New classes are additional classes, old syntax will persists for BC. With this `/page-templates/full-width.php` will produce `page-template`, `page-template-page-templates`, `page-template-full-width` and `page-template-page-templatesfull-width-php`. props obenland, Caspie, donutz. fixes #23470. git-svn-id: https://develop.svn.wordpress.org/trunk@30100 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post-template.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php index 7145a21d16..6535af15ab 100644 --- a/src/wp-includes/post-template.php +++ b/src/wp-includes/post-template.php @@ -615,7 +615,14 @@ function get_body_class( $class = '' ) { } if ( is_page_template() ) { $classes[] = 'page-template'; - $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_page_template_slug( $page_id ) ) ); + + $template_slug = get_page_template_slug( $page_id ); + $template_parts = explode( '/', $template_slug ); + + foreach ( $template_parts as $part ) { + $classes[] = 'page-template-' . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) ); + } + $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', $template_slug ) ); } else { $classes[] = 'page-template-default'; }