block editor - Register multiple stylesscripts in register_block_type

admin2025-01-07  3

I use following code to register my Gutenberg Block:

register_block_type('create-block/myblock', array(
    'editor_script' => 'create-block-myblock-script-editor',
    'script' => 'create-block-myblock-script',
    'editor_style' => 'create-block-myblock-style-editor',
    'style' => 'create-block-myblock-style-1',
));
// register scripts & styles
wp_register_script('create-block-myblock-script-editor', $urlScriptEditor, array());
wp_register_script('create-block-myblock-script', $urlScript, array());
wp_register_style('create-block-myblock-style-editor', $urlEditor, array());
wp_register_style('create-block-myblock-style-1', $urlOne, array());

Now I want to register a second stylesheet for the front-end:

wp_register_style('create-block-myblock-style-2', $urlTwo, array());

How can I hook into the block register as only one script is intended for each case?

I use following code to register my Gutenberg Block:

register_block_type('create-block/myblock', array(
    'editor_script' => 'create-block-myblock-script-editor',
    'script' => 'create-block-myblock-script',
    'editor_style' => 'create-block-myblock-style-editor',
    'style' => 'create-block-myblock-style-1',
));
// register scripts & styles
wp_register_script('create-block-myblock-script-editor', $urlScriptEditor, array());
wp_register_script('create-block-myblock-script', $urlScript, array());
wp_register_style('create-block-myblock-style-editor', $urlEditor, array());
wp_register_style('create-block-myblock-style-1', $urlOne, array());

Now I want to register a second stylesheet for the front-end:

wp_register_style('create-block-myblock-style-2', $urlTwo, array());

How can I hook into the block register as only one script is intended for each case?

Share Improve this question edited Aug 12, 2020 at 11:37 User Rebo asked Jul 27, 2020 at 22:08 User ReboUser Rebo 2212 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Not supported yet, see the corresponding Github Issue. I found a workaround in order to at least register additional block styles:

register_block_style(
    'create-block/myblock', array(
        'name'         => 'style2',
        'label'        => 'Style 2',
        'style_handle' => 'create-block-myblock-style-2',
    )
);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736257126a414.html

最新回复(0)