#41518 closed defect (bug) (wontfix)
The full-path body class is missing a hyphen.
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.9 |
Component: | Posts, Post Types | Keywords: | close |
Focuses: | template | Cc: |
Description
In a case where page templates (eg "full-width.php") are in a folder called "templates" - a body class is created called "page-template-templatesfull-width-php". This is because post-template.php line 611 sanitizes the file path without replacing "/" with a hyphen like it does for template name parts on line 609.
I suggest replacing 611 with
$classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( array( '.', '/' ), '-', $template_slug ) );
Change History (4)
#2
@
8 years ago
Hi @SergeyBiryukov Thanks and I understand! I might just be new to the format but I'm not seeing the comments surrounding https://core.trac.wordpress.org/changeset/30100. The backwards compatibility you mention would only go back to 3.4 (when template subfolders were first supported), right?
I'm getting the feeling there isn't really a good folder/file naming structure that results in all the classes making sense - as page-template-page-templates
is semantically silly, too.
#3
@
4 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
Hello @isaaclubow,
You can see the backwards compatibility discussion in the closed ticket #23470. The missing hyphen was a decision decision for backwards compatibility. Changing it could be a breaking change.
I'll go ahead and close this ticket as it was marked for close
some years ago and likely will not be fixed due to impacts from backward compatibility.
Hi @isaaclubow, welcome to WordPress Trac! Thanks for the ticket.
We can't just change the way these classes are built due to backwards compatibility concerns, see #23470 / [30100].
In the example above, a page with a
/page-templates/full-width.php
template would have the following classes:page-template
,page-template-page-templates
,page-template-full-width
, andpage-template-page-templatesfull-width-php
.