WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#11331 closed enhancement (wontfix)

get_body_class() does not include page-{slug}-php

Reported by: westonruter Owned by:
Milestone: Priority: low
Severity: trivial Version: 3.0
Component: General Keywords: has-patch 2nd-opinion
Focuses: Cc:

Description

I have a Glossary page whose slug is "glossary". I created a page-glossary.php to utilize the new WP 2.9 functionality. I was expecting that "page-glossary-php" to be listed among the classNames but instead "page-template-default" was included. Maybe this would better be manifested as a "page-slug-glossary" className just as there is a "page-id-XX".

Attachments (3)

body-class.patch (660 bytes) - added by garyc40 4 years ago.
11331.diff (556 bytes) - added by coffee2code 4 years ago.
Passes slug through sanitize_html_class()
11331.b.diff (3.5 KB) - added by coffee2code 4 years ago.
Same as 11331.diff, but with spaces added to calls in that function. Separate issue, sure, but it's localized, trivial, and one step towards coding standards compliance.

Download all attachments as: .zip

Change History (10)

comment:1 scribu4 years ago

  • Keywords needs-patch added
  • Milestone changed from 2.9 to 3.0

All enhancements are punted to 3.0.

garyc404 years ago

comment:2 garyc404 years ago

  • Keywords has-patch 2nd-opinion added; needs-patch removed
  • Version changed from 2.9 to 3.0

added page-slug-xxxxx as a class name for all pages, not just for pages with custom page template file.

comment:3 coffee2code4 years ago

The slug should get passed through sanitize_html_class() to ensure only valid characters are used, as is done for the other slug-based class names. See 11331.diff.

coffee2code4 years ago

Passes slug through sanitize_html_class()

coffee2code4 years ago

Same as 11331.diff, but with spaces added to calls in that function. Separate issue, sure, but it's localized, trivial, and one step towards coding standards compliance.

comment:5 follow-up: nacin4 years ago

I'm not sure about this. With this patch, we may be generating some very long class names, and I don't think we use slugs anywhere else in body|post_class.

We already support page template names and page IDs, we don't support post slugs for example, only post IDs.

comment:6 nacin4 years ago

(In [13468]) Add some whitespace to get_body_class(). props coffee2code. Clarify fallback parameter in sanitize_html_class(). see #11331

comment:7 in reply to: ↑ 5 scribu4 years ago

  • Milestone 3.0 deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Replying to nacin:

I'm not sure about this. With this patch, we may be generating some very long class names, and I don't think we use slugs anywhere else in body|post_class.

I agree.

If you really need this, you have the 'body_class' filter.

Besides, you can add extra CSS from your page-glossary.php template:

<?php

function extra_styles() {
  wp_enqueue_style('glossary', get_bloginfo('stylesheet_directory') . '/glossary.css');
}
add_action('wp_print_styles', 'extra_styles');

get_header();

...
Note: See TracTickets for help on using tickets.