Is it possible to print the output of a Gunteberg block with no classes?

Question

The following code comes from one of the Gutenberg blocks official examples. The block is pretty simple and just create an editable field that outputs a p element.

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 }
            />
        );
    },
    save: ( props ) => {
        return <RichText.Content tagName="p" value={ props.attributes.content } />;
    },
} );

If used, this block produces a p element with a class like this:

<p class="wp-block-gutenberg-examples-example-03-editable-esnext"></p>

which I’m assuming is built upon the registerBlockType parameter.

My question is: is it possible to print the output of a custom block without any class specification?

edit: WordPress docs say there is a filter to change the default class name, which is this:

wp.hooks.addFilter(
  'blocks.getBlockDefaultClassName',
  'my-plugin/set-block-custom-class-name',
  setBlockCustomClassName
);

Now, where exactly does this code go? Can’t find it in the docs.

0
Nico Vecchio 11 months 0 Answers 46 views 0

Leave an answer