WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 3 months ago

#23470 new defect (bug)

Convert slash to dash and make body class for page templates look better

Reported by: Caspie Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.4
Component: Themes Keywords: has-patch
Focuses: template Cc:

Description

If you keep you page templates in a page-templates folder in your theme. Let's we have a template named front-page.php - the template slug written in the postmeta will be page-templates/front-page.php

When generating the classes for the body, get_body_class() will convert the dot to a dash but the slash will be stripped by sanitize_html_class().
So finally we will have a class:

page-template-page-templatesfront-page-php

Isn't it prettier to convert the slash to dash and to have it like:

page-template-page-templates-front-page-php

Attachments (2)

23470.diff (613 bytes) - added by Caspie 14 months ago.
23470bis.diff (643 bytes) - added by donutz 14 months ago.

Download all attachments as: .zip

Change History (7)

Caspie14 months ago

comment:1 ocean9014 months ago

  • Version changed from 3.5.1 to 3.4

Page templates in subdirs are supported since 3.4, see #11216.

Fixing it could break some themes. :(

donutz14 months ago

comment:2 follow-up: donutz14 months ago

  • Cc donutz added

I would like to make a case for fixing it.

First, something like page-template-page-templatesfront-page-php looks quite horrible, not to say buggy or erratic. I wouldn't use such a selector in my stylesheet :)

Second, moving templates to a sub-folder (and thus being forced to reapply them) breaks things as well (css), one expects to have access to the same body class selector, template located in sub-folder or not.

Third, it could be useful to have the sub-folder name as a separate body class, so one could group a bunch of templates and style them all in one go.

I attached a diff file with a possible solution.

comment:3 in reply to: ↑ 2 nacin14 months ago

Replying to donutz:

I would like to make a case for fixing it.

First, something like page-template-page-templatesfront-page-php looks quite horrible, not to say buggy or erratic. I wouldn't use such a selector in my stylesheet :)

Agree.

Second, moving templates to a sub-folder (and thus being forced to reapply them) breaks things as well (css), one expects to have access to the same body class selector, template located in sub-folder or not.

Disagree. When a template is moved to a subfolder, all posts using that page template break. I see no reason why the CSS class shouldn't also change.

Third, it could be useful to have the sub-folder name as a separate body class, so one could group a bunch of templates and style them all in one go.

Clever idea.

comment:4 tillkruess13 months ago

  • Cc me@… added

comment:5 nacin3 months ago

  • Component changed from Template to Themes
  • Focuses template added
Note: See TracTickets for help on using tickets.