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?
-
Sure, but could you post the code you've worked thus far when you tried to get this to work? How to create a Minimal, Complete, and Verifiable example– admcfajnOct 14, 2018 at 19:55
-
@admcfajn there is no code, as far as I know for this, recommended in the Gutenberg docs. I can think of a few hacky ways to remove it but I'm interested in an official way of doing it, and so are many people because it's not documented. That's the point of the question.– CyberJOct 14, 2018 at 20:18
-
Here's try this out, there's a handful of custom blocks in this repo you can dig into: github.com/WordPress/gutenberg-examples/blob/master/03-editable/…– admcfajnOct 14, 2018 at 21:02
2 Answers
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.
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 } />;
},
} );
-
2That's a placeholder for a paragraph richtext element not the initial block placeholder. Answer should be removed.– CyberJNov 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.– admcfajnNov 23, 2018 at 20:17