-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FSE: Add support for body_class and post_class #29308
Comments
FSE themes already use the body_class and this can still be filtered |
The PR just adds the existing get_post_class() function, I wonder if we need to consider what classes are added and if any of them are redundant? |
@carolinan Revising post classes might cause backwards compatibility issues for some plugins or child themes that rely on particular classes. Not saying we shouldn't revise, just wanted to keep that in mind. |
There will still be issues because traditionally themes have a an article (or div) around both header, content and meta information. FSE does not have "post areas", the only consistent wrapper is the div that already has the entry-content class. It is possible to place it on the query loop list markup, but then it will not affect single views. |
Do we even want to add all these classes? |
There are two sides to that 🤔 |
I assumed there were accessibility reasons for supporting |
You are already able to add those, by filtering the body class. |
The |
Thanks. My suggestion is that core adds |
If core adds the <script>document.body.classList.remove('no-js');</script> I don't believe we want to add any scripts on the front - no matter how simple they are. At least not at this point AFAIK 🤔 Without the script that class is meaningless and will do more harm than good... Core doesn't need that class on the frontend because it doesn't load any scripts on the front for blocks, so I think it would be fine to skip it. If any plugins/themes need to check for that class they always add it on their own |
I guess this can be closed then... |
I'm still confused. The question remains if the post_class() should be added or not and on which block -post content, or querly loop? Before: After: These are the classes I was wondering if we really want to add: Perhaps only the post id and type should be added? Post format? |
I agree with @aristath FSE should be as cleaner as possible, adding thoose CSS class should not be made by core when possible.
I don't think we need them, for a client I added a custom css class with |
@scruffian I am not sure why this was closed, was a conclusion reached elsewhere? I'd like to know if I should also close #29412. |
I closed it because I hadn't yet seen a good example of when they are needed. I see in #29412 you're adding |
Those are default classes, see https://developer.wordpress.org/reference/functions/get_post_class/ Without the post_class function, the filter to adjust the classes also can't be used. The hentry should probably avoided. But this still leaves the question about where these classes should be output. On the content block or somewhere else? |
format-standard usage: type-post usage: |
Asking why we need conditional classes? Simple. A user asks how they can add a purple border to only their posts with the "Super Duper" category. I say, "Add this code to your CSS:"
Without the class, I say, "Sorry, WordPress no longer allows you to do cool stuff like this. Look for another piece of software or switch to a classic theme." If anything, I'd like us to adopt an entire attribute system, not just limiting to classes. The class system is overly limiting for more advanced features. I doubt that will happen, so let's keep the system in place. We can reevaluate and remove core-output classes. However, theme authors should be able to filter them. |
On the content block would be the wrong place and would create back-compat issues for any old themes transitioning to FSE. It should be on a wrapper element for the entire post. Not sure how that will work. There really should be a "Post" block, even if it only exists as a container for nested blocks. |
I'd expect this kind of feature to live in the query block, not as part of a theme. |
The feature I described really isn't part of the theme. Users can customize their CSS regardless of theme. However, I cannot imagine how crazy the Query block would have to be to cover the endless amounts of customization for the conditionals that exist. This is just one extremely tiny example for a basic border. Will the Query block have conditional styling options for every single class that currently exists? We know it won't. It never will. Each use case on its own is an edge case. Altogether, they represent a needed feature. |
My suggestion is that the query block could output a class, like we currently do on the body... |
The Query block wraps all posts, not individual posts. Or, are you talking about having the Query block inject the post class around each post? |
The query-loop block already wraps each post in a |
What problem does this address?
Classic themes add
no-js
,singular
,hfeed
,has-main-navigation
andno-widgets
classes to the body. Gutenberg should also do this for block themes.We also need to look at what we add for
post_class
and add support for that too.From #22724.
The text was updated successfully, but these errors were encountered: