Opened 21 months ago
Closed 21 months ago
#57422 closed defect (bug) (duplicate)
get_body_class() adding class "{$post_type}-template-{dir}{file}"
Reported by: | arrancurran | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 6.1.1 |
Component: | Posts, Post Types | Keywords: | |
Focuses: | css, template | Cc: |
Description (last modified by )
When is_singular()
and is_page_template()
and the template file is inside a directory within the theme folder, get_body_class()
adds a class with a missing hyphen between the template directory and the template file name.
post-template.php
line 677;
$classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( '.', '-', $template_slug ) );
Example: post_type
is page and template file is, page-templates/my-template-file.php
Result: .page-template-page-templatesmy-template-file-php
Suggested change to post-template.php
line 677;
$classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( array( '.', '/' ), '-', $template_slug ) );
Change History (3)
Note: See
TracTickets for help on using
tickets.
Hi there, welcome to WordPress Trac! Thanks for the report.
Replying to arrancurran:
This was previously discussed in #23470 and improved in [30100] in a way that is similar to the suggestion here.
With the example above, a class like this should also be added:
.page-template-page-templates-my-template-file
However, the consensus was that the old class needs to remain for backward compatibility and cannot be removed.