# Restrict the Code Editor to Administrators

> Hides the "Code editor" mode of the block editor from everyone except administrators, so other users only edit visually.

- Type: PHP
- Runs: Run everywhere
- Category: [Block Editor](https://wpide.com/library/category/gutenberg/)
- Tags: block-editor, code-editor, roles
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/code-editor-admins-only/

## Code

```php
add_filter( 'block_editor_settings_all', function ( $settings ) {
    if ( ! current_user_can( 'manage_options' ) ) {
        $settings['codeEditingEnabled'] = false;
    }

    return $settings;
} );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Restrict the Code Editor to 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/
