古登堡更改/删除自定义块中的“编写您的故事”占位符

时间:2018-10-13 作者:CyberJ

当创建新页面或帖子或专栏块时,我们会得到“写你的故事”占位符。是否可以在自定义块中删除或替换?怎样

enter image description here

2 个回复
最合适的回答,由SO网友:Danny Cooper 整理而成

似乎有一个过滤器可以修改默认值:https://github.com/WordPress/gutenberg/blob/master/lib/client-assets.php#L1574

\'bodyPlaceholder\'        => apply_filters( \'write_your_story\', __( \'Write your story\', \'gutenberg\' ), $post ),
所以你应该可以使用WordPressadd_filter() 作用

SO网友:admcfajn

下面是一个示例块,取自WordPress/gutenberg-examples 添加占位符文本。

const { __, setLocaleData } = wp.i18n;
const { registerBlockType } = wp.blocks;
const { RichText } = wp.editor;

setLocaleData( window.gutenberg_examples_03_esnext.localeData, \'gutenberg-examples\' );

registerBlockType( \'gutenberg-examples/example-03-editable-esnext\', {
    title: __( \'Example: Editable (esnext)\', \'gutenberg-examples\' ),
    icon: \'universal-access-alt\',
    category: \'layout\',
    attributes: {
        content: {
            type: \'array\',
            source: \'children\',
            selector: \'p\',
        },
    },
    edit: ( props ) => {
        const { attributes: { content }, setAttributes, className } = props;
        const onChangeContent = ( newContent ) => {
            setAttributes( { content: newContent } );
        };
        return (
            <RichText
                tagName="p"
                className={ className }
                onChange={ onChangeContent }
                value={ content }
                placeholder={__(\'wpse316624 placeholder text\', \'custom-block\')}
            />
        );
    },
    save: ( props ) => {
        return <RichText.Content tagName="p" value={ props.attributes.content } />;
    },
} );

结束

相关推荐