我们首先通过以下方式找出存在哪些块样式.getBlockTypes()
. 这会将其转储到控制台:
wp.domReady(() => {
// find blocks styles
wp.blocks.getBlockTypes().forEach((block) => {
if (_.isArray(block[\'styles\'])) {
console.log(block.name, _.pluck(block[\'styles\'], \'name\'));
}
});
});
输出示例:
core/image (2) ["default", "rounded"]
core/quote (2) ["default", "large"]
core/button (2) ["fill", "outline"]
core/pullquote (2) ["default", "solid-color"]
core/separator (3) ["default", "wide", "dots"]
core/table (2) ["regular", "stripes"]
core/social-links (3) ["default", "logos-only", "pill-shape"]
有了这些信息,我们可以根据需要停用块样式。例如,如果要删除
large
报价样式,我们可以在
remove-block-styles.js
:
wp.domReady(() => {
wp.blocks.unregisterBlockStyle(\'core/quote\', \'large\');
} );
我们可以加载
remove-block-styles.js
在主题中
functions.php
:
function remove_block_style() {
// Register the block editor script.
wp_register_script( \'remove-block-style\', get_stylesheet_directory_uri() . \'/remove-block-styles.js\', [ \'wp-blocks\', \'wp-edit-post\' ] );
// register block editor script.
register_block_type( \'remove/block-style\', [
\'editor_script\' => \'remove-block-style\',
] );
}
add_action( \'init\', \'remove_block_style\' );
如果要删除所有块样式(如上所列),可以使用:
wp.domReady(() => {
// image
wp.blocks.unregisterBlockStyle(\'core/image\', \'rounded\');
wp.blocks.unregisterBlockStyle(\'core/image\', \'default\');
// quote
wp.blocks.unregisterBlockStyle(\'core/quote\', \'default\');
wp.blocks.unregisterBlockStyle(\'core/quote\', \'large\');
// button
wp.blocks.unregisterBlockStyle(\'core/button\', \'fill\');
wp.blocks.unregisterBlockStyle(\'core/button\', \'outline\');
// pullquote
wp.blocks.unregisterBlockStyle(\'core/pullquote\', \'default\');
wp.blocks.unregisterBlockStyle(\'core/pullquote\', \'solid-color\');
// separator
wp.blocks.unregisterBlockStyle(\'core/separator\', \'default\');
wp.blocks.unregisterBlockStyle(\'core/separator\', \'wide\');
wp.blocks.unregisterBlockStyle(\'core/separator\', \'dots\');
// table
wp.blocks.unregisterBlockStyle(\'core/table\', \'regular\');
wp.blocks.unregisterBlockStyle(\'core/table\', \'stripes\');
// social-links
wp.blocks.unregisterBlockStyle(\'core/social-links\', \'default\');
wp.blocks.unregisterBlockStyle(\'core/social-links\', \'logos-only\');
wp.blocks.unregisterBlockStyle(\'core/social-links\', \'pill-shape\');
} );
主要学分至
Per Søderlind 对于代码段。