12

When the Block Editor was added to WordPress, custom and core meta boxes became legacy, meaning, using the remove_meta_box() function won't work when removing meta boxes/panels displayed on the post editing screen.

So, how do we remove the Excerpt panel when we can't use remove_meta_box() anymore?

6 Answers 6

28

The remove_meta_box() function will not work with the Block Editor, because these are now Panels and work differently. There is currently no documentation on how to disable Panels, but, let's dance.

We want to avoid hiding panels via CSS, and rely on the JS API.

We need to use the JS function removeEditorPanel() which will completely remove the panel with all its controls:

// remove excerpt panel
wp.data.dispatch( 'core/edit-post').removeEditorPanel( 'post-excerpt' );

Here is an (incomplete) list of panel IDs:

  • taxonomy-panel-category - Category panel.
  • taxonomy-panel-CUSTOM-TAXONOMY-NAME - Custom taxonomy panel. If your taxonomy is topic, then taxonomy-panel-topic works.
  • taxonomy-panel-post_tag - Tags panel
  • featured-image - Featured image panel.
  • post-link - Permalink panel.
  • page-attributes - Page attributes panel.
  • post-excerpt - Post excerpt panel.
  • discussion-panel - Discussions panel.
  • template - Template panel added with WP 5.9.

The full code

PHP (in your functions.php or custom plugin):

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' );

The JS file (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

How about other panels?

If you know the ID of other panel than the ones listed above, please leave a comment.

On some panels, there is the alternative to to hide the panel via CSS. For example, to hide the Revisions panel, we can use:

.components-panel__body.edit-post-last-revision__panel {
    display:none !important;
}

Inspect the element of the panel to located the class name (edit-post-last-revision__panel). Note that some panels do not have unique class names.

So, register you block style:

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',
) );

And include your CSS code into the block-style.css file.

5
  • Also you can disable post status using wp.data.dispatch( 'core/edit-post').removeEditorPanel( 'post-status' ) ;.
    – Kalimah
    Commented Oct 26, 2020 at 3:27
  • How do I find the ID of a custom panel. Is there a way to list the panels and their IDs in the Javascript console?
    – Chris
    Commented Mar 15, 2021 at 17:33
  • jQuery('.postbox') in browser console should give you the meta box ids, and prepend id like this ``` wp.data.dispatch( 'core/edit-post').removeEditorPanel( 'meta-box-mb-id' ); ```
    – Syed
    Commented Jun 17, 2021 at 14:26
  • FYI here’s how to remove the new “Template” meta box that was added in WP 5.9 (it’s no longer located within Page Attributes) wp.data.dispatch('core/edit-post').removeEditorPanel('template'); Commented Feb 22, 2022 at 17:05
  • Very helpful, Thanks! Also take a look at Oceandigitals answer which shows how to do it without creating any js files.
    – ggedde
    Commented Feb 16 at 7:38
7

Addition to Christine Coopers answer https://wordpress.stackexchange.com/a/339437/31140

How to remove non-core meta boxes

If you want to remove panels that were added by themes or plugins, proceed like this:

  1. Find the PANEL-ID by inspecting the HTML code:
    Run jQuery('.postbox') in your browsers JS console.
    jQuery will find all custom meta boxes for you!
    You need to identify the correct box and copy the element ID. Find the Panel-ID
  2. The internal panel ID of the meta box is meta-box-<PANEL-ID>

Example

// Remove the DIVI meta-box:
var boxId = 'et_settings_meta_box_gutenberg';
wp.data.dispatch( 'core/edit-post').removeEditorPanel( 'meta-box-' + boxId );

// Remove an ACF meta-box:
var boxId = 'acf-group_5d9b020a3db4e';
wp.data.dispatch( 'core/edit-post').removeEditorPanel( 'meta-box-' + boxId );

How to remove core panels

See Christine Coopers answer https://wordpress.stackexchange.com/a/339437/31140

2

To hide meta_box from Block Editor and display them only in classic editor add arg __back_compat_meta_box set to true when adding meta box

add_meta_box( 'my-meta-box', 'My Meta Box', 'my_meta_box_callback',
    null, 'normal', 'high',
    array(
        '__back_compat_meta_box' => true,
    )
); 
1
  • 1
    This wasn't what I was asking for specifically, but still good to know. ;)
    – Christine Cooper
    Commented Jul 5, 2019 at 10:59
2

And this is how to get a list of core panel IDs:

wp.data.select( 'core/edit-post' ).getPreferences().panels;
2

I found a faster solution, you can just add this functions in php. This for example disables tags:

add_action('admin_head', 'webroom_add_css_js_to_admin');
function webroom_add_css_js_to_admin() {
 echo '<script>
 wp.domReady( () => {
  const { removeEditorPanel } = wp.data.dispatch("core/edit-post");
  // Remove featured image panel from sidebar.
  removeEditorPanel( "taxonomy-panel-post_tag" );
  } );
  </script>';
}
2
  • Thank you! Not sure why everyone wants to jump to JS and create a bunch of extra random files.
    – ggedde
    Commented Feb 16 at 7:36
  • People may want to check if the wp.domReady function exists beforehand, and core/edit-post has been changed to core/editor.
    – MarcGuay
    Commented Dec 9 at 21:59
-1

This one worked for me.

function remove_post_support() {
    remove_post_type_support('post','excerpt');     
}
add_action('init','remove_post_support');
1
  • You are not hiding anything; you are removing the support altogether. So, if your theme uses excerpts on the front-end, it won't work. Commented Mar 19 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.