这个remove_meta_box() 该函数将不会与块编辑器一起使用,因为它们现在是面板,工作方式不同。目前没有关于如何禁用面板的文档,但是,让我们跳舞吧。
我们希望避免通过CSS隐藏面板,并依赖JSAPI。
我们需要使用JS函数removeEditorPanel() 将完全移除面板及其所有控件:
// remove excerpt panel
wp.data.dispatch( \'core/edit-post\').removeEditorPanel( \'post-excerpt\' );
 以下是面板ID的(不完整)列表:
- taxonomy-panel-category- Category 面板
- taxonomy-panel-CUSTOM-TAXONOMY-NAME- Custom taxonomy 面板如果您的分类是- topic, 然后- taxonomy-panel-topic工作
- taxonomy-panel-post_tag- Tags 面板- featured-image- Featured image 面板
- post-link- Permalink 面板
- page-attributes- Page attributes 面板
- post-excerpt- 邮递excerpt 面板
- discussion-panel- Discussions 面板
- template- Template 添加WP 5.9的面板
完整代码functions.php 或自定义插件):
function cc_gutenberg_register_files() {
    // script file
    wp_register_script(
        \'cc-block-script\',
        get_stylesheet_directory_uri() .\'/js/block-script.js\', // adjust the path to the JS file
        array( \'wp-blocks\', \'wp-edit-post\' )
    );
    // register block editor script
    register_block_type( \'cc/ma-block-files\', array(
        \'editor_script\' => \'cc-block-script\'
    ) );
}
add_action( \'init\', \'cc_gutenberg_register_files\' );
 JS文件(
block-script.js):
wp.data.dispatch( \'core/edit-post\').removeEditorPanel( \'taxonomy-panel-category\' ) ; // category
wp.data.dispatch( \'core/edit-post\').removeEditorPanel( \'taxonomy-panel-TAXONOMY-NAME\' ) ; // custom taxonomy
wp.data.dispatch( \'core/edit-post\').removeEditorPanel( \'taxonomy-panel-post_tag\' ); // tags
wp.data.dispatch( \'core/edit-post\').removeEditorPanel( \'featured-image\' ); // featured image
wp.data.dispatch( \'core/edit-post\').removeEditorPanel( \'post-link\' ); // permalink
wp.data.dispatch( \'core/edit-post\').removeEditorPanel( \'page-attributes\' ); // page attributes
wp.data.dispatch( \'core/edit-post\').removeEditorPanel( \'post-excerpt\' ); // Excerpt
wp.data.dispatch( \'core/edit-post\').removeEditorPanel( \'discussion-panel\' ); // Discussion
wp.data.dispatch( \'core/edit-post\').removeEditorPanel( \'template\' ); // Template
 其他面板怎么样如果您知道上述面板以外的其他面板的ID,请留下评论。
在某些面板上,可以通过CSS隐藏面板。例如,要隐藏Revisions 面板,我们可以使用:
.components-panel__body.edit-post-last-revision__panel {
    display:none !important;
}
 检查面板的元素以定位类名(
edit-post-last-revision__panel). 请注意,某些面板没有唯一的类名。
因此,注册您的块样式:
wp_register_style(
    \'cc-block-style\',
    get_stylesheet_directory_uri() .\'/inc/block-style.css\', // adjust file path
    array( \'wp-edit-blocks\' )
);
register_block_type( \'cc/ma-block-files\', array(
    \'editor_style\' => \'cc-block-style\',
) );
 并将CSS代码包含到
block-style.css 文件