Disable Gutenberg via Code + Plugin
-
Thank you very much for this plugin Jeff, its much appreciated. I have installed your plugin on all my sites, and have also added the following code to functions.php.
add_filter(‘gutenberg_can_edit_post_type’, ‘__return_false’);
I did this as a backup in the event that the plugin is accidentally disabled. Do you seen any issues with this?
Kind regards.
-
Hi kmbee,
I am glad to help, but not sure if that one line is enough to disable Gutenberg. I definitely would test before going live.
Cheers.
Oh okay, I found that code on an article you posted on https://digwp.com/2018/04/how-to-disable-gutenberg/.
“To completely disable Gutenberg (aka G7G), add the following line via functions.php or custom plugin (or even a must-use plugin!):
add_filter(‘gutenberg_can_edit_post_type’, ‘__return_false’);
That’s the recommended way of disabling Gutenberg. It simply returns a value of false to Gutenberg’s gutenberg_can_edit_post_type filter, which then disables G7G for all post types (i.e., completely). To disable only on specific post types, check out the next technique.”
I will test. Thank you.
Well then there you go! Lol, I should not have been so lazy and checked it for myself. Anyway, If you’ve got both the code and that line in functions.php, you should be good to go for disabling Gutenberg.
-
This reply was modified 7 years, 9 months ago by
Jeff Starr.
Hehe no worries Jeff, thanks for the confirmation!
Hi Jeff, I see that there is updated code to completely disable Gutenberg in functions.php. I found the code at https://digwp.com/2018/04/how-to-disable-gutenberg/
I have now included the new code, but also left the old code in place. Do you see any potential problems with this? The following is how I have it in functions.php
// Disable Gutenberg – Newer
add_filter(‘use_block_editor_for_post’, ‘__return_false’);// Disable Gutenberg – Older
add_filter(‘gutenberg_can_edit_post_type’, ‘__return_false’);I also have the Disable Gutenberg plugin installed. Will the code in functions.php interfere with the plugin at all?
Thank you again Jeff
Hi kmbee,
If you are using Disable Gutenberg plugin, you don’t need to add any manual code. The plugin takes care of everything for you.
But if you just want to know about the code FWIW, what you have is the right idea, but may want to add some conditional logic to keep things clean, for example:
// Disable Gutenberg if (version_compare($GLOBALS['wp_version'], '5.0-beta', '>')) { // WP > 5 beta add_filter('use_block_editor_for_post_type', '__return_false', 100); } else { // WP < 5 beta add_filter('gutenberg_can_edit_post_type', '__return_false'); }From there you would want to wrap it in a function and hook into plugins_loaded or similar. But again, this is just FYI; if you are using the plugin you do not need to add any code.
I’ll go ahead and update the DigWP article with this conditional snippet 🙂
-
This reply was modified 7 years, 6 months ago by
Jeff Starr. Reason: adds info
-
This reply was modified 7 years, 6 months ago by
Jeff Starr. Reason: adds info
Perfect Jeff, thanks so much. I have the code in functions.php as a backup just in case the plugin is disabled.
I see that the version “5.0-beta” is in the code. Do I have to edit the version in the code with each WordPress update?
Nope. That is the version when Gutenberg was merged into core. No need to edit anything.
-
This reply was modified 7 years, 6 months ago by
Jeff Starr.
Hi Jeff, I notice that there is a change to the conditional method posted at https://digwp.com/2018/04/how-to-disable-gutenberg/. Do I need to use the updated code?
What I have now is;
// Disable Gutenberg
if (version_compare($GLOBALS[‘wp_version’], ‘5.0-beta’, ‘>’)) {// WP > 5 beta
add_filter(‘use_block_editor_for_post_type’, ‘__return_false’, 100);} else {
// WP < 5 beta
add_filter(‘gutenberg_can_edit_post_type’, ‘__return_false’);}
The update I see is;
// Disable Gutenberg
if (version_compare($GLOBALS[‘wp_version’], ‘5.0-beta’, ‘>’)) {
// WP > 5 beta
add_filter(‘use_block_editor_for_post_type’, ‘__return_false’, 10);} else {
// WP < 5 beta
add_filter(‘gutenberg_can_edit_post_type’, ‘__return_false’, 10);}
Thank you
Yes the new code is current, should be fine with either though. The difference is the value set in the third parameter of each
add_filter()function. Previously it was set to 100, but a value of 10 is the default and recommended. -
This reply was modified 7 years, 9 months ago by
The topic ‘Disable Gutenberg via Code + Plugin’ is closed to new replies.