问题描述
此代码应能够基于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 );
解决方法
原来我使用的是古腾堡的旧版本,最新版本9+允许此代码按预期工作。