- This topic has 7 replies, 2 voices, and was last updated 4 years, 5 months ago by
Elvin.
-
AuthorPosts
-
October 31, 2021 at 8:00 pm #1985927
Ash
Would be nice if you could add “class” input field to the Layout metabox on post editing screen.(any post type)
Since css does not have “parent” selector, ability of adding custom class to body tag would be useful to style certain pages.October 31, 2021 at 8:52 pm #1985955Elvin
StaffCustomer SupportHi Ash,
The body tag has a lot of classes already. There’s a unique class for the page or post itself (example:
postid-1orpage-id-1), and there’s already one for the post type(example:single-post) as well.I’m not sure how this is necessary considering what’s already added. Can you explain a bit more about it?
Let us know. 😀
October 31, 2021 at 9:35 pm #1985967Ash
Using post id is a bad practice I think.
If I duplicate it or recreate as different post, the style won’t be inherited.
Also it’s not convenient way to style multiple pages at once.October 31, 2021 at 9:58 pm #1985976Elvin
StaffCustomer SupportUsing post id is a bad practice I think.
Not exactly. If it’s specific to a page then it’s good because this particular class will never change. It’s assigned to the post as its unique identification number (hence postid).
If you’re targeting post types, there’s already one for that as I’ve mentioned on the previous post.
This article explains the rest of the classes being added by WordPress by default.
https://webdesign.tutsplus.com/tutorials/adding-to-the-body-class-in-wordpress–cms-21077And with the filter, we can actually create own on “meta field” for body classes using ACF.
Example: Assuming you’ve already created a
additional_body_classACF field.add_filter( 'body_class','add_body_classes' ); function add_body_classes( $classes ) { $addclass = get_field('additional_body_class'); if($addclass){ $classes[] = $addclass; } return $classes; }which will add class added to the ACF field
additional_body_class.October 31, 2021 at 11:36 pm #1986039Ash
Ok, it was not proper word – bad practice.
But clients often ask page redesign without using a staging site so I have to duplicate or recreate the page.
Using post id is very inconvenient. it will cause headache every time I redesign.
it’s “bad” at least for me in some situation.It’s possible by using additional custom field like you said.
but I thought there are many people who is in the same situation out there.
So this cloud be useful.October 31, 2021 at 11:57 pm #1986049Elvin
StaffCustomer SupportUsing post id is very inconvenient. it will cause headache every time I redesign.
It’s meant for styling a single specific page. If you’re styling multiple pages or post then you shouldn’t use post ids. You should use post types or taxonomy classes. 😀
I do recognize specific situations like having a handy body class for specific pages so you don’t have to list CSS like this:
body.postid-1 .entry-content p a, body.postid-2 .entry-content p a, body.postid-3 .entry-content p a, { }and do it cleanly w/ an assigned body class to each post with this:
body.assigned-class .entry-content p a {}but since there are many ways of doing this (programmatically w/ WP Core filter
body_class+is_page(), through Hook elements + display rule, ACF +body_classfilter, etc ), this may be taken as a niche feature.I’ve logged it as a feature request for you but since niche features like this one rarely gets requested so it we can’t guarantee it gets implemented.
That said, if there’s an immediate need for something like this, you can use the workaround for now. 😀
November 1, 2021 at 12:05 am #1986058Ash
Understand, thank you.
November 1, 2021 at 12:16 am #1986065Elvin
StaffCustomer SupportNo problem. Glad to be of any help. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.