Find out in this tutorial how to hide code editor of WordPress editor from non-administrators using code.
With the arrival of the block editor and Full Site Editing (FSE) to WordPress one of the concerns of designers and developers is that the end user has “too much” control over the design and can disrupt the work of the professional.
That’s why a very interesting option would be to make the code editor that allows to modify the blocks HTML only accessible according to the user role
For example? That only administrators have access to it.
This way you make sure that the client does not make modifications that should not be made.
Access to the code editor can be done in a general way or in each block:
And with this tutorial you are going to hide both. Let’s see how.
Show blocks code editor only to WordPress administrators
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
In this code you use the block_editor_settings_all
filter in conjunction with the current_user_can
function to allow only administrators to access the code editor.
Once applied, non-admin users will not see the option to edit code, either in the general settings or at the block level:
Conclusion
Now you know how to hide the code editor of WordPress editor from users who do not have admin role.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉