此代码应该能够基于https://wordpress.stackexchange.com/questions/324091/add-classname-to-gutenberg-block-wrapper-in-the-editor
然而,它没有,任何帮助都将不胜感激
const { createHigherOrderComponent } = wp.compose;
const withCustomClassName = createHigherOrderComponent( ( BlockListBlock ) => {
return (props) => {
if (props.name !== 'core/heading') return <BlockListBlock {...props} />
const { attributes } = props
return <BlockListBlock { ...props } className={ "custom-classes-" + attributes.fontSizeChoice } />
};
}, 'withCustomClassName');
wp.hooks.addFilter( 'editor.BlockListBlock', 'custom-name/heading-with-custom-class-name', withCustomClassName );
原来我使用的是Gutenburg的旧版本,最新的9+版本允许此代码按预期工作。