如何将自定义块添加到WordPress Gutenberg块?

如何将自定义块添加到WordPress Gutenberg块?,wordpress,wordpress-gutenberg,gutenberg-blocks,Wordpress,Wordpress Gutenberg,Gutenberg Blocks,我想为古腾堡创建一个新的自定义块,可以吗 是的,这是可能的。我建议您使用类似的初学者工具包来创建古腾堡积木 ⚡️ 快速概述 一次性快速运行步骤#1和#2-在本地WP安装中运行,例如/WP.local/WP-content/plugins/目录 npx create-guten-block my-block cd my-block npm start 阅读上的所有详细信息是的,这是可能的。读这本书。这里有很多这样的例子: // init.php function gutenberg_boiler

我想为古腾堡创建一个新的自定义块,可以吗

是的,这是可能的。我建议您使用类似的初学者工具包来创建古腾堡积木

⚡️ 快速概述

一次性快速运行步骤#1和#2-在本地WP安装中运行,例如/WP.local/WP-content/plugins/目录

npx create-guten-block my-block
cd my-block
npm start

阅读

上的所有详细信息是的,这是可能的。读这本书。这里有很多这样的例子:

// init.php
function gutenberg_boilerplate_block() {
    wp_register_script(
        'gutenberg-boilerplate-es5-step01',
        plugins_url( 'step-01/block.js', __FILE__ ),
        array( 'wp-blocks', 'wp-element' )
    );

    register_block_type( 'gutenberg-boilerplate-es5/hello-world-step-01', array(
        'editor_script' => 'gutenberg-boilerplate-es5-step01',
    ) );
}
add_action( 'init', 'gutenberg_boilerplate_block' );


// block.js:
var el = wp.element.createElement,
    registerBlockType = wp.blocks.registerBlockType,
    blockStyle = { backgroundColor: '#900', color: '#fff', padding: '20px' };

registerBlockType( 'gutenberg-boilerplate-es5/hello-world-step-01', {
    title: 'Hello World (Step 1)',

    icon: 'universal-access-alt',

    category: 'layout',

    edit: function() {
        return el( 'p', { style: blockStyle }, 'Hello editor.' );
    },

    save: function() {
        return el( 'p', { style: blockStyle }, 'Hello saved content.' );
    },
} );