以防万一有人来看我,我就是这么做的。首先,我将一个javascript文件排入块编辑器。
add_action( \'enqueue_block_editor_assets\', function () {
wp_enqueue_style( \'block-editor-styles\', get_template_directory_uri(\'styles/gutenberg.css\'), false, \'1.0\', \'all\' );
wp_enqueue_script( \'block-editor-scripts\', get_template_directory_uri(\'scripts/gutenberg.js\'), array( \'wp-blocks\', \'wp-dom\' ), time(), true );
});
然后我就用这段代码添加了一个列变体。
wp.domReady( function () {
wp.blocks.registerBlockVariation(
\'core/columns\', {
name: \'two-columns-two-thirds-one-third-eighty-twenty\',
title: \'80/20\',
description: \'Two columns; two-thirds, one-third split\',
icon: \'<svg />\',
innerBlocks: [
[\'core/column\', { width: \'80%\' }],
[\'core/column\', { width: \'20%\' }],
],
scope: [\'block\'],
}
);
});