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
This commit is contained in:
parent
f6544f237a
commit
15af3fdaa8
|
@ -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';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue