Opened 8 years ago
Last modified 8 years ago
#39493 new enhancement
Include custom post type slug as body class
Reported by: | danielbachhuber | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | has-patch |
Focuses: | Cc: |
Description
If I have a custom post type product
and a post with slug laptop
, then I can create a single-product-laptop.php
template to render markup specific to this product.
But, a template needs styles too. It would be easier to target my CSS specific to this template if single-product-laptop
was included as a body class.
Attachments (2)
Change History (6)
#3
in reply to:
↑ 2
@
8 years ago
Replying to SergeyBiryukov:
Previously suggested in #18118, wontfixed as an "antipattern".
For this thread, @ericlewis's comment:
I think this is an antipattern.
Slugs are mutable by content editors. I've been bitten by implementing what's suggested here and having clients change slugs, then they lose styling on X page and not knowing why.
I don't think Eric's comment is consistent with WordPress' existing behavior.
In the scenario I described initially, the template is loaded based on the post slug. If the slug were to change, then the template would no longer load.
#4
@
8 years ago
- Keywords has-patch added
39493.2.diff adjusts the patch from #18118 and includes unit tests.
CSS classes support Unicode characters, so ideally this should support multibyte post slugs in a way similar to #37655, but apparently #33924 is a blocker for that.
add body class single-{post_type_slug}-{post_name}