How to Disable the Visual Editor in WordPress

Home » Snippets » How to Disable the Visual Editor in WordPress

Created with:



Creator: WPTurbo Team

Customize with WPTurbo AI

Add Snippet To Project

New Project
Add To Existing Project

Are you tired of the visual editor in WordPress causing formatting issues and messing with your code? If you prefer to work with pure HTML and want to disable the visual editor in WordPress, you’re in the right place. In this article, we’ll guide you through the process of disabling the visual editor and give you the freedom to work directly with your code.

					function wpturbo_disable_visual_editor() {
    add_filter('user_can_richedit', '__return_false', 50);
add_action('admin_init', 'wpturbo_disable_visual_editor');

The code snippet provided above is used to disable the visual editor in WordPress. This can be useful in situations where you want to restrict users from using the visual editor and only allow them to edit content in the text editor.

The first part of the code defines a function called wpturbo_disable_visual_editor(). This function uses the add_filter() function to add a filter to the user_can_richedit hook. The user_can_richedit hook allows you to control whether a user can access the visual editor.

Inside the add_filter() function, we pass two parameters. The first parameter is the user_can_richedit hook, which is the hook that we are targeting. The second parameter is __return_false, which is a WordPress callback function that will set the value to false. This effectively disables the visual editor for all users.

The next step is to hook the wpturbo_disable_visual_editor() function into the admin_init action. The admin_init action is triggered when the admin area of WordPress is initialized.

By hooking the function into the admin_init action, this ensures that the function is executed when the admin area is loaded, allowing it to disable the visual editor before it is rendered.

Overall, this code snippet is a simple and effective way to disable the visual editor in WordPress. By using the user_can_richedit hook and the add_filter() function, we can easily modify the behavior of the visual editor and restrict its usage for specific users or roles.

Register an account to save your snippets or go Pro to get more features.