-
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
Generate body class for Gutenberg pages & provide helper function #4418
Comments
Hi to @maddisondesigns .
I am sorry if you knew PS |
@pm-hiroshi Thanks for that. I wasn't aware that |
We used to think that |
I think a |
@mtias That would be fine. Thanks. It obviously makes sense to get away from the name 'Gutenberg' so as long as there's something that we can use, both in php and css, I don't really mind what it's called. |
Can you help me better understand what that body class is for?
Do you mean the HTML/CSS class structure here or displaying a gallery differently? |
@obenland Yep, the html/css. The html/css that is output on the front-end is significantly different when using Gutenberg, compared to using the Classic Editor. As someone who has themes on .org, we're now going to need to support both editors in our theme so it would be great if Gutenberg added a body class so as to help us style for the different editors. Likewise, it would also be good to have a helper function so that our PHP can know what editor is being used for the current page. Something like |
I'm just having reservations when it comes to adding a Core body class because that class will have to be supported for the rest of time. And with a future so close where every post will be made out of blocks, having a
Gutenberg currently comes with the |
There are going to be tens of thousands of sites that aren't using blocks and will be using the Classic Editor. For our Themes on .org. it's also imperative that they continue to support the Classic Editor whilst adding new features for Gutenberg. With that said, this issue was raised almost 7 months ago and obviously a lot has changed since then. I've been able to get around the lack of a body class so far, so it's probably not quite as important anymore.
As far as I'm aware, |
Merges `gutenberg_post_has_blocks()` and `gutenberg_content_has_blocks()`, resulting in a template function that can be used context-independently. It accepts a content string, a post object, or post ID, and default to the current post if none of those are given. Make this part of the API behave close to existing WordPress template functions. It's my first Gutenberg PR, so I'd love to get feedback on this, especially around a better phpunit setup potentially? See #4418.
The function `gutenberg_content_has_blocks` is deprecated as of version 3.6.0. The discussion leading up to the change can be found [here](WordPress/gutenberg#4418) and the PR which was merged 2 days ago can be found [here](WordPress/gutenberg#8631).
I was actually implementing similar body class in my theme a week ago. Then it occurred to me and I'm with @obenland in opinion on such class. We shouldn't actually apply any class just because the Gutenberg is used on the post/page. Gutenberg will become standard and what will we do with the class then...? ;) If anybody really needs such a class, just implement the functionality into your theme. But for making your theme future proof, I'd suggest using negative class, something like: function themeprefix_body_class_blocks( $classes ) {
if ( is_singular() && ! has_blocks() ) {
$classes[] = 'has-no-blocks';
}
return $classes;
}
add_filter( 'body_class', 'themeprefix_body_class_blocks' ); Then you can apply specific styles to Gutenberg pages using But than again, once you update your theme for Gutenberg in the future, you will most likely rewrite the CSS, so it's really up to you if you use |
Leaving this is in user land seems good for now. It can always be added later if the need becomes more clear. |
Issue Overview
I think that it's pretty obvious by now that there's a large portion of the WP community that are still going to need to continue to use the classic editor once WP5.0 ships. Not only that, when providing themes in the .org Theme Directory, it's going to be important that the theme supports both the classic editor as well as the new Gutenberg markup.
I know it's been mentioned (briefly) in the past on a ticket somewhere, but that discussion never went anywhere. I think it's important that WP adds a new
gutenberg
body class to any pages that are rendered by Gutenberg. The styles required to render content from the classic editor and also from Gutenberg, are going to be significantly different and we need a way to know what editor is rendering the page.Likewise, it would also be good to have a helper function so that our PHP can know what editor is being used for the current page. Something like
is_gutenberg()
. This will be helpful if people want to enqueue different stylesheets or scripts, depending on what editor is being used.I think it's important that these are supported core functions as well, rather than just adhoc code snippets that we have to manually add to each of our themes to get this sort of functionality.
The text was updated successfully, but these errors were encountered: