-
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
Setting to disable Layout controls #31980
Comments
I'm curious to hear the reasoning for this. |
I'm building custom websites for clients. And I would like to keep the interface as clean as possible. Currently I'm trying to disable as many controls as I can, mainly leaving only the color controls on block-level. And I believe one of the goals of the theme.json is to configure "What customization options should be made available or hidden from the user." (Handbook) |
Additional thought: by default inherit default layout. And if the theme-developer disables custom content width than don't show the layout options at all. Reference to design proposal: #31950 (comment) |
I'm in a similar position as @erikjoling and want to disable panel for our clients, since most of the designs are very customized. Therefore it's possible to set the support of the entire group block-type to disallow editing - which in my case fit's fine. I will set the layout attributes only in a pattern or via a custom block-variation. addFilter(
"blocks.registerBlockType",
"pluginname/group",
(settings, name) => {
if (name !== "core/group") {
return settings;
}
const newSettings = {
...settings,
supports: {
...(settings.supports || {}),
layout: {
...(settings.supports.layout || {}),
allowEditing: false,
allowSwitching: false,
allowInheriting: true,
},
__experimentalLayout: {
...(settings.supports.__experimentalLayout || {}),
allowEditing: false,
allowSwitching: false,
allowInheriting: true,
},
},
};
return newSettings;
},
20
); This still applies the correct layout/flex-styles, but hides the LayoutPanel. I found that only adding FYI: This only works when run outside a ❗ Right now the layout-key is still experimental, I'm setting un-prefixed key as well - but will have to keep an eye on changes to the layout-support config. |
Hi folks, any updates on this? Gaambo's solution works (thanks!), but I believe that this should be solved via theme.json. I build very custom themes and clients don't want to be able to toggle with the layout width - they want to see only settings which are supported and sometimes it's pretty hard since the new features are popping out of nowhere... |
This is labelled as an enhancement, which I understand. But as far as people creating themes go, this is 100% a bug that should be resolved quickly. |
I've found a solution that nukes this whole panel from every block in Gutenberg from the PHP side. /**
* Filter block type metadata to remove unwanted output from the editor.
*
* @param array $metadata Metadata for the currently processed block type.
*
* @return array Filtered metadata.
*/
public function filter_block_type_metadata( $metadata ) {
/**
* Disable the layout panel for all blocks.
*/
if ( isset( $metadata['supports']['__experimentalLayout'] ) ) {
$metadata['supports']['__experimentalLayout'] = false;
}
return $metadata;
}
add_filter( 'block_type_metadata', 'filter_block_type_metadata' ); Props to @samikeijonen for putting me in the right direction! |
Seems the use case raised by @Luehrsen in core channel: "Is there a way to disable the block layout panel through theme.json without killing alignwide and alignfull?" @carolinan wrote "Theme.json overrides the theme support, it is not possible to not use the layout setting, but add the "old" theme support." |
To be more precise: Our work requires very strict control about what an editor can customise and what is off limits. For many reasons, including legal and retaining design consistency, we cannot just teach this issue away by telling editors to ignore this field. That is why we disable the CSS output generated by this control with Again: The ability to have VERY tight control over what CSS is output in the frontend and which controls are shown to the user is absolutely essential to a lot of currently implemented use cases in the real world. Breaking these use cases leads to only one outcome: People not updating their WordPress systems anymore and a gradual loss of trust in the systems to either updates breaking sites or WordPress being insecure (because updates are breaking sites). |
I think there are a few different suggestions being discussed, I want to try and clarify the use cases:
I agree 1 and 2 seem reasonable and would be useful, though there are probably some considerations I'm missing. One related issue I don't think mentioned yet is over here #36082 with some mockups on how the layout controls could be improved. I am not sure I captured 3 correctly, or if it needs more clarification:
@Luehrsen how are you suggesting the layout CSS to be modified? Or is it just the ability to disable it entirely? |
Hey @jffng, thank you for asking. Right now I'm in the "deactivate it completely" camp. But my stance is a result from this panel giving a lot of power to editors and it generating a lot of ugly, repetitive CSS output in the body. |
I agree we should be able to disable this entirely, AND also maintain control over the width settings for inner blocks. As a theme developers we all have our own systems for managing widths of blocks. We need the ability to offer minimal options when appropriate but this is not a control that I want to leave wide open to site editors. It also generates so much unnecessary CSS in the body of the page... |
I agree with this. I have a theme using CSS Grid for all layout, integrated with the "Inherit default layout" toggle. This approach to layout means a child container is not necessarily constrained by the width of its parent container — a noted limitation of the current layout model using max-width with horizontal auto margins. There are times when the Layout panel could be/should be a valid option but Gutenberg doesn't expose it. In this situation, it would be ideal to opt-in a specific block for layout support: for example, perhaps via an attribute added to a block's markup in a pattern or template. Theme developers will benefit from more control over where (opt-in; globally or targeted) and if (enable/disable) layout support is available. |
I would also like the ability to disable this field. It is confusing that you can't add
Strangely, this doesn't work even though it seems like it should. |
If you're looking to disable the Layout panel for one specific block type, here's an example using the Column block. This is similar to what @Luehrsen provided, except it focuses on one block type, instead of all of them. function filter_metadata_registration( $metadata ) {
if ( $metadata['name'] === 'core/column' ) {
$metadata['supports']['__experimentalLayout'] = false;
}
return $metadata;
};
add_filter( 'block_type_metadata', 'filter_metadata_registration' ); Ideally this would be possible in |
You can also accomplish this via JavaScript on a block-by-block basis:
|
Thanks for the feedback everyone! Disabling layout controls via theme.json has been implemented in #53378. For those seeking to remove layout styles altogether, that's already possible since WP 6.1 with In order to disable the controls from theme.json, the required property is This is can already be used with the Gutenberg plugin and will be available in core in WP 6.4. |
@gaambo Thank you! the code works to hide the layout UI controls, but is there a way to toggle off 'Inner blocks use content width' by default, so the div is full width instead of set to constraint? |
@rose18Developer Since WordPress 6.4 there's a new If you're still using the previous workaround, in the past I've used those keys:
|
Thanks @gaambo ! The code help to hide the UI control, but by default, the 'Inner blocks use content width' is enabled, making the div constraint, screenshot below: I want by default to toggle off the 'Inner blocks use content width', so the container is full width, screenshot below: Is there a way to toggle of the 'Inner blocks use content width' when the core group block is added? Thanks! |
@rose18Developer that's a bit trickier because the layout for the default Group type is set in its variations, which are used when inserting a new block. You could potentially create a new variation and set it as default; see these docs for more info. Edit: you would want your variation to have the |
What problem does this address?
I would like to be able to disable layout controls.
What is your proposed solution?
Inside theme.json the layout setting (general and block) should decide whether the layout controls are visible. For example
The text was updated successfully, but these errors were encountered: