# Hide Editor Panels From Non-Administrators

> Removes rarely needed panels like Discussion, Custom Fields and the slug box from the editor for everyone but administrators, in both editors.

- Type: PHP
- Runs: Admin only
- Category: [Admin](https://wpide.com/library/category/admin/)
- Tags: admin, editor, meta-boxes
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/hide-editor-panels-non-admins/

## Code

```php
// Block editor panel names => classic editor meta box IDs to hide.
$wpide_hidden_panels = array(
    'discussion-panel' => array( 'commentstatusdiv', 'commentsdiv', 'trackbacksdiv' ),
    'post-link'        => array( 'slugdiv' ),
    'page-attributes'  => array( 'pageparentdiv' ),
);

// Classic editor meta boxes without a block editor panel.
$wpide_hidden_meta_boxes = array( 'postcustom' );

add_action( 'add_meta_boxes', function ( $post_type ) use ( $wpide_hidden_panels, $wpide_hidden_meta_boxes ) {
    if ( current_user_can( 'manage_options' ) ) {
        return;
    }

    $boxes = $wpide_hidden_meta_boxes;

    foreach ( $wpide_hidden_panels as $ids ) {
        $boxes = array_merge( $boxes, $ids );
    }

    foreach ( $boxes as $box ) {
        foreach ( array( 'normal', 'advanced', 'side' ) as $context ) {
            remove_meta_box( $box, $post_type, $context );
        }
    }
}, 99 );

add_action( 'enqueue_block_editor_assets', function () use ( $wpide_hidden_panels ) {
    if ( current_user_can( 'manage_options' ) ) {
        return;
    }

    $script = sprintf(
        'wp.domReady(function(){var s=wp.data.dispatch("core/editor");if(!s||!s.removeEditorPanel){s=wp.data.dispatch("core/edit-post");}%s.forEach(function(p){s.removeEditorPanel(p);});});',
        wp_json_encode( array_keys( $wpide_hidden_panels ) )
    );

    wp_add_inline_script( 'wp-edit-post', $script );
} );
```

## Notes

Edit the two lists to choose which panels stay hidden.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Hide Editor Panels From Non-Administrators" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
