-
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
No class added to body tag in editor for active page/post template #8948
Comments
Hi @jlvngs96 — I took a look in the classic editor on a few sites I maintain and the active template is not applied as a class on the backend; only on the front-end. I totally agree that this would be nice to have but unfortunately it has been raised a few times (#8162 and #7810 in particular) but it seems unlikely it'll happen. That said I'll let someone else from the Gutenberg core team chime in — I think the issue has been raised enough that it should definitely be reconsidered. I know I'd like to see it myself! |
Oooh, interesting. I was looking at the actual body class. I can confirm it's there for me too. In that case this might qualify as a backcompat issue. I'll tag it and let's see what the other folks say! |
Hi guys, I'm all for this to be included. I actually have the exact same issue as @jlvngs96 experiences. Was using the classes to target specific page/post template editor appearance and I think this should be kept in Gutenberg too. Also, in my opinion it would be better if such classes are applied onto actual Gutenberg editor content area, not on admin body. So, on If you can, could you also please allow filtering such classes. Currently, for example, it is possible to filter TinyMCE classes via Thanks! |
Hi, Looking forward to this feature! |
Hi guys (@chrisvanpatten), Any update on this issue? Will the functionality be integrated with Gutenberg? As my themes actually rely on page template body class change in TinyMCE editor, I'm still hesitating to update them for Gutenberg compatibility because the feature is not integrated in Gutenberg. As you can understand that would basically mean downgrading the user experience which I don't really want to do… Thanks for any update provided! |
Keen for this as well - we have some different block styling depending on the template you're on to better reflect the front-end. This works fine on CPT, as the CPT is in the body class, but there's no template class here as yet. For now I'm going to need to add in some custom JS to achieve this, but it would be super useful going forwards. |
@eddhurst Can you share the JavaScript you end up using so I can add to my Gutenberg Migration Guide? |
Looking at the way Gutenberg manipulates the classes - it's actually just hooking in and adding to the filter admin_body_class This was fine for my purposes, so after I've manipulated my custom blocks I add in a hook to add in my class which already fires in the correct place so keeps it nice and tidy. If you look in gutenberg.php, you can see on lines 192 and 486 how Gutenberg itself hooks into this: /gutenberg.php: Line 192 /gutenberg.php: Line 487 The way that WordPress looks to handle this, if we look at admin-header.php: https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-admin/admin-header.php#L197 It initialises the body with all the various classes: And then below this adds in the following JS: If you wanted to do it in JS - this approach should work fine too. |
I'm actually also using JS to dynamically apply template class on Gutenberg's
This is basically an adapted version of original WordPress code and obviously, this is an example of a PHP function outputting the JS ;) |
I'm closing this issue in order to consolidate with #10640 and would like to note the discussion here has been useful and helpful and it will be linked from the other issue. Sometimes it's hard to choose which to keep when there are duplicates—in this case, the #10640 issue seemed better to me because it's very clear and concise and I am interested in keeping the easiest-to-grok issues open where possible. Thank you for testing Gutenberg at this stage and for your open discussion on this topic! |
@webmandesign |
@foreverpinetree Here's an alternative: #8162 (comment) |
Based on the code here, I made a little tutorial (sage9 based theme): https://discourse.roots.io/t/gutenberg-body-class-elements-by-template/15310 |
In the classic editor, a body class is added to the editor, indicating the active post/page template. This is very useful when creating the editor specific stylesheet during theme development so the editor matches styles on the front end. For example, my default single post has a sidebar, but I also have a full width post/page template that removes the sidebar. So in the classic editor a body class is added for "page-template-full-width" for example, that lets me target that in the editor stylesheet. Would like this same functionality for Gutenberg. This is important so if the default is active, the editor body is one width, and if a page template is selected, the editor body is another width.
The text was updated successfully, but these errors were encountered: