From 4df00e156db2adc7d461346ea429c7b3f4c60805 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Wed, 29 Oct 2014 22:20:23 +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. Built from https://develop.svn.wordpress.org/trunk@30100 git-svn-id: http://core.svn.wordpress.org/trunk@30100 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post-template.php | 9 ++++++++- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index 7145a21d16..6535af15ab 100644 --- a/wp-includes/post-template.php +++ b/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'; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 1c14ea9beb..b012a7bb58 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.1-alpha-30099'; +$wp_version = '4.1-alpha-30100'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.