WordPress.org

Make WordPress Core

Changeset 30100


Ignore:
Timestamp:
10/29/14 22:19:08 (3 years ago)
Author:
ocean90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-template.php

    r30036 r30100  
    616616        if ( is_page_template() ) { 
    617617            $classes[] = 'page-template'; 
    618             $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_page_template_slug( $page_id ) ) ); 
     618 
     619            $template_slug  = get_page_template_slug( $page_id ); 
     620            $template_parts = explode( '/', $template_slug ); 
     621 
     622            foreach ( $template_parts as $part ) { 
     623                $classes[] = 'page-template-' . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) ); 
     624            } 
     625            $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', $template_slug ) ); 
    619626        } else { 
    620627            $classes[] = 'page-template-default'; 
Note: See TracChangeset for help on using the changeset viewer.