3

When created a new page or post or columns blocks we get the "Write your story" placeholder. Can this be removed or replaced, in custom blocks? How?

enter image description here

3

2 Answers 2

4

There does seem to be a filter to modify the default: https://github.com/WordPress/gutenberg/blob/master/lib/client-assets.php#L1574

'bodyPlaceholder'        => apply_filters( 'write_your_story', __( 'Write your story', 'gutenberg' ), $post ),

So you should be able to use the WordPress add_filter() function.

0

Here's an example block taken from WordPress/gutenberg-examples with placeholder text added.

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 } />;
    },
} );
2
  • 2
    That's a placeholder for a paragraph richtext element not the initial block placeholder. Answer should be removed.
    – CyberJ
    Nov 5, 2018 at 12:23
  • I agree with you CyberJ, but since Gutenberg is still pretty new I'll leave it up just in case it helps point someone in the right direction.
    – admcfajn
    Nov 23, 2018 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.