Remove the "Code editor" option from the block editor for everyone except administrators.
add_filter( 'block_editor_settings_all', function ( array $settings ): array {
if ( ! current_user_can( 'manage_options' ) ) {
$settings['codeEditingEnabled'] = false;
}
return $settings;
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
The block editor’s Code editor shows a post’s raw block markup. Editing it by hand is an easy way to break blocks. This snippet removes the option for non-administrators.
codeEditingEnabled in the editor settings controls whether the “Code editor” switch appears in the Options menu. The snippet sets it to false for users without manage_options.
html support.Log in as an editor, open the editor’s Options menu, and check that “Code editor” is missing.