How to remove "full" alignment option? #47359
Replies: 3 comments 2 replies
-
Hey, you can use the following filter hook for this: https://developer.wordpress.org/block-editor/reference-guides/filters/block-filters/#blocks-registerblocktype Example: function removeAlignOption( settings, name ) {
if (!settings) return settings;
if (!settings?.supports) settings.supports = {};
if (settings.supports?.align) settings.supports.align = false;
return settings;
}
wp.hooks.addFilter(
'blocks.registerBlockType',
'my-plugin/remove-align/all-blocks',
removeAlignOption
); |
Beta Was this translation helpful? Give feedback.
-
Thank you for the response! I'm having trouble getting this to execute. I would assume all this sort of stuff should be wrapped in wp.domReady, but maybe I'm wrong about that? Here is my attempt to follow your suggestion:
Aside -- how did you get JS syntax highlighting in your comment? |
Beta Was this translation helpful? Give feedback.
-
Thanks. Sure, I understand a filter must always return the value passed into it. I've attempted this again, with slightly better results outside of the domReady. But I still am not getting the expected behavior, see: function removeAlignOption( settings, name ) {
if( name != 'core/image' ) { return settings; }
if( ! settings ) return settings;
console.log( 'this guy logs' );
if ( ! settings?.supports ) {
settings.supports = {};
}
if ( settings.supports?.align ) {
console.log( 'this guy doesnt log' );
settings.supports.align = false;
}
return settings;
}
wp.hooks.addFilter(
'blocks.registerBlockType',
'my-plugin/remove-align/all-blocks',
removeAlignOption
); So it seems that for some reason the settings.supports enters this hook with no support for align at all, and I'm not sure why. |
Beta Was this translation helpful? Give feedback.
-
See screenshot. I don't want to support a "full" width in my theme. What is the themes.json entry, or php filter, or wp js api approach for filtering those buttons out?
Beta Was this translation helpful? Give feedback.
All reactions