While there already are similar questions around this topic I have yet to find anything about disabling the Code editor in Gutenberg permanently, for all users:

Code editor

Using Gutenberg is a must, so I'm not looking for solutions regarding the classic editor or alternative editor plugins.

A code snippet that disables the editor would be much welcomed (I don't want to use a UI-only option). If this can't be achieved through hooks in the backend, I would also accept solutions that only affect the front end (since the backend receives HTML regardless of the editor used). Using display: none to hide the option would be one way to do it but I'd prefer a more permanent solution.

The main reason for this is for security. I have already disabled many blocks and the patterns.

I have already tried returning false on wp_code_editor_settings but that did not do anything to the Gutenberg editor.

  • 1
    Looking at the source code. There doesn't appear to be a way to do this. Hiding the option with CSS is the best you're going to do, but that won't stop the keyboard shortcut from working, so you'd just be making it hard to fix the issue if the user switched accidentally. Feb 15, 2023 at 13:16
  • 1
    I'm curious what security issues you think you're solving by doing this though? Feb 15, 2023 at 13:16
  • @JacobPeattie The idea is that the user could insert custom HTML into the code editor which I want to prevent. While it might not prevent someone from doing it in other means, it would greatly reduce support requests when they think they know what they're doing but in reality they don't. It might break certain pages or not have desired behavior and that is to be avoided. The other reason is that corporate cyber security asks to mitigate this which means, even if it is not reasonable to disable, they're still expecting mitigation. Feb 15, 2023 at 14:00
  • Ok, fair enough. Unfortunately you’re out of luck, as this doesn’t seem to be possible. Feb 15, 2023 at 14:28

1 Answer 1


Disable the code editor by hooking into the block_editor_settings_all filter:

    static function (array $settings): array {
        $settings['codeEditingEnabled'] = false;
        return $settings;

See the documentation for more options.

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.