Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何注册样式、脚本和;WordPress Gutenberg块编辑器的块_Wordpress_Wordpress Gutenberg_Gutenberg Blocks - Fatal编程技术网

如何注册样式、脚本和;WordPress Gutenberg块编辑器的块

如何注册样式、脚本和;WordPress Gutenberg块编辑器的块,wordpress,wordpress-gutenberg,gutenberg-blocks,Wordpress,Wordpress Gutenberg,Gutenberg Blocks,我已经为编辑器创建了一些自定义块,这些块可以正常工作,但是CSS有问题 blocks.editor.build.css加载到编辑器和前端,它应该只加载到编辑器中 blocks.style.build.css应该在两个位置加载,但不在任何位置加载 还有,有没有更好的方法来注册块,这样我就不必为我创建的每个新块重复register\u block\u type()代码 function my_register_custom_blocks() { // Editor JS wp_reg

我已经为编辑器创建了一些自定义块,这些块可以正常工作,但是CSS有问题

blocks.editor.build.css
加载到编辑器和前端,它应该只加载到编辑器中

blocks.style.build.css
应该在两个位置加载,但不在任何位置加载

还有,有没有更好的方法来注册块,这样我就不必为我创建的每个新块重复
register\u block\u type()
代码

function my_register_custom_blocks() {
    // Editor JS
    wp_register_script(
        'my-custom-blocks',
        plugins_url('/blocks/dist/blocks.build.js', __FILE__),
        array('wp-blocks', 'wp-element', 'wp-editor', 'wp-components')
    );

    // Frontend & Editor Styles  
    wp_register_style(
        'my-custom-blocks-style',
        plugins_url( '/blocks/dist/blocks.style.build.css', __FILE__ ),
        array( 'wp-blocks' )
    );

    // Editor Only Styles
    wp_register_style(
        'my-custom-blocks-edit-style',
        plugins_url('/blocks/dist/blocks.editor.build.css', __FILE__),
        array( 'wp-edit-blocks' )
    );  

    // Divder Block
    register_block_type('custom-blocks/divider', array(
        'editor_script' => 'my-custom-blocks',
        'editor_style' => 'my-custom-blocks-edit-style',
        'style' => 'my-custom-blocks-style'
    ));

    // Spacer Block
    register_block_type('custom-blocks/block-spacer', array(
        'editor_script' => 'my-custom-blocks',
        'editor_style' => 'my-custom-blocks-edit-style',
        'style' => 'my-custom-blocks-style'
    ));

    ...More Blocks
}

add_action('init', 'my_register_custom_blocks');

您可以使用的结构,这样您就需要使用这些脚本/样式一次

├── .gitignore
├── plugin.php //add plugin info and add init.php file
├── package.json
├── README.md
|
├── dist
|  ├── blocks.build.js
|  ├── blocks.editor.build.css
|  └── blocks.style.build.css
|
└── src
   ├── block
   |  ├── block.js
   |  ├── editor.scss
   |  └── style.scss
   |
   ├── blocks.js // import each new block here to show up on editor
   ├── common.scss
   └── init.php // register scripts & styles here

您可以使用的结构,这样您就需要使用这些脚本/样式一次

├── .gitignore
├── plugin.php //add plugin info and add init.php file
├── package.json
├── README.md
|
├── dist
|  ├── blocks.build.js
|  ├── blocks.editor.build.css
|  └── blocks.style.build.css
|
└── src
   ├── block
   |  ├── block.js
   |  ├── editor.scss
   |  └── style.scss
   |
   ├── blocks.js // import each new block here to show up on editor
   ├── common.scss
   └── init.php // register scripts & styles here