Skip to content

Add template file for changing a block's styles #55

Description

@2ndTwo

The template file should be something like the following and be in the src/js directory:

wp.domReady( () => {
    const unregisterBlockStyle = wp.blocks.unregisterBlockStyle;
    const registerBlockStyle = wp.blocks.registerBlockStyle;

    // Remove some block styles

    // unregisterBlockStyle( 'core/button', 'fill' );


    // Add custom styles to blocks

    /*
    registerBlockStyle( 'core/paragraph', [
        {
            name: 'default',
            label: 'Default',
            isDefault: true,
        },
        {
            name: 'cta',
            label: 'Call to Action',
        },
    ]);
    */
});

The block style script also needs to be enqueued in the inc/block-editor.php file:

wp_enqueue_script(
	'sabino-editor',
	get_stylesheet_directory_uri() . '/js/JS_FILE.js',
	array( 'wp-blocks', 'wp-dom' ),
	time(),
	true
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or requestjavascriptEdits that modify JavaScript filesphpEdits that modify PHP files

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions