# Turn Off "Edit as HTML" on Blocks for Non-Administrators

> Removes the "Edit as HTML" option from block menus for everyone except administrators, so authors cannot break block markup by hand.

- Type: PHP
- Runs: Run everywhere
- Category: [Block Editor](https://wpide.com/library/category/gutenberg/)
- Tags: block-editor, permissions, html
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/no-edit-as-html-for-non-admins/

## Code

```php
add_filter( 'block_type_metadata', function ( $metadata ) {
    if ( current_user_can( 'manage_options' ) || empty( $metadata['name'] ) ) {
        return $metadata;
    }

    $metadata['supports']         = isset( $metadata['supports'] ) ? (array) $metadata['supports'] : array();
    $metadata['supports']['html'] = false;

    return $metadata;
} );
```

## Notes

Administrators keep the option. The Code editor mode is a separate setting.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Turn Off "Edit as HTML" on Blocks for 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/
