Make WordPress Core

Opened 8 years ago

Closed 4 years ago

Last modified 2 years ago

#41518 closed defect (bug) (wontfix)

The full-path body class is missing a hyphen.

Reported by: isaaclubow's profile isaaclubow 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)

#1 @SergeyBiryukov
8 years ago

  • Keywords close added

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, and page-template-page-templatesfull-width-php.

#2 @isaaclubow
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 @hellofromTonya
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.

#4 @SergeyBiryukov
2 years ago

#57422 was marked as a duplicate.

Note: See TracTickets for help on using tickets.