Opened 23 months ago
Last modified 22 months ago
#18118 new feature request
Append page slug to body_class function
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Themes | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: |
Description
I actually do this already on all of my sites, and thought this would be an obvious, amazing thing to add to the body_class function. Pretty much what you'd expect; the page-slug gets appended to the body_class, allowing for page-specific styling.
<?php body_class($post->post_name . ' '); ?>
Attachments (1)
Change History (6)
comment:1
johnbillion — 23 months ago
comment:2
SergeyBiryukov — 22 months ago
Closed #18220 as duplicate.
comment:3
DennisSmolek — 22 months ago
It wont need a prefix as the body tag already gets the post type as a part of the class object. you would just use .post.page-title {}
There are two ways, one as a functions.php add on, the other as a part of the core file. You would want to check if its post/page because they have different name functions.
There is actually an example of this somewhere in the codex..
comment:4
DennisSmolek — 22 months ago
this looks right:
http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/post-template.php
add to line 330:
$classes[] = $post->post_name;
SergeyBiryukov — 22 months ago
comment:5
SergeyBiryukov — 22 months ago
- Keywords has-patch added

Probably needs a prefix to the slug, eg page-my-page instead of just my-page. Might be an idea to do it for all hierarchical CPTs.