Search code examples
phpcsswordpressbootstrap-4wordpress-gutenberg

Curiosity, how do you manage the Gutenberg block previews in the admin area?


How can I manage gutenberg block previews in the admin area?

Example:
If I have a block developed on bootstrap and with my custom css, in the admin area do you load bootstrap and your css to get the preview?


Solution

  • You can load custom css and javascript for every block like described in the block editor handbook. However it might not be a good idea to load bootstrap only for one block.

    You can choose to supply style and editor_style in your register_block_type function. The first gets loaded in front + back, the latter only in the backend.

    register_block_type( 'gutenberg-examples/example-02-stylesheets', array(
        'style' => 'gutenberg-examples-02',
        'editor_style' => 'gutenberg-examples-02-editor',
        'editor_script' => 'gutenberg-examples-02',
    ) );