在编辑器中向Gutenberg块包装器添加其他类

时间:2020-09-09 03:40:44

标签: javascript reactjs wordpress wordpress-gutenberg gutenberg-blocks

此代码应能够基于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 );

1 个答案:

答案 0 :(得分:0)

原来我使用的是古腾堡的旧版本,最新版本9+允许此代码按预期工作。