Enable / Disable Gutenberg by Category
-
Hello,
I have a large website that was originally developed with Divi and ACF, before Gutenberg was launched. And all posts are currently styled with those two. So, I’m kinda stuck with it.
Until now, I have used the ‘classic editor’ plugin to disable Gutenberg on the site, as it’s not used.
But I want to use Gutenberg on a new type of post I will be adding. As I find it quicker and simpler to use than Divi.
So, I want to disable Gutenberg globally, so the site continues to appear as it has done until now. BUT I want to enable Gutenberg on the new kind of post I will be creating.
I found this post explaining how to do it:
https://digwp.com/2018/12/enable-gutenberg-block-editor/
Changing the global disable instructions to version 6, in my theme functions file, as follows:
// WP < 6.0 beta
add_filter(‘gutenberg_can_edit_post’, ‘__return_false’, 5);// WP >= 6.0
add_filter(‘use_block_editor_for_post’, ‘__return_false’, 5);[QUESTION 1: I changed // WP < 5.0 beta to // WP < 6.0 beta, etc, BUT should the
return_false’, 5); ???
be also changed to
return_false’, 6); ???Then I followed the instructions to enable Gutenberg on a specific post category, as that seemed most appropriate for my uses. And it seems to work ok, BUT I need to add it to multiple categories and cannot figure out how to add an array of category IDs or an ‘IF OR’ conditional.
QUESTION 2: Can anyone please look at the following I added to Functions, below the above script, and tell me how to make it work on an array of categories?
function shapeSpace_enable_gutenberg_post_cats($can_edit, $post) { if (empty($post->ID)) return $can_edit; if (has_category(12)) return true; return $can_edit; // Enable Gutenberg for WP < 6.0 beta add_filter('gutenberg_can_edit_post', 'shapeSpace_enable_gutenberg_post_cats', 10, 2); // Enable Gutenberg for WordPress >= 6.0 add_filter('use_block_editor_for_post', 'shapeSpace_enable_gutenberg_post_cats', 10, 2);
EG: My categories are ‘2007’ and 2022′ this script seems to work if I replace:
if (has_category(12)) return true;
with
if (has_category(2007)) return true;
But I cannot figure out how to add further categories — I tried commas and || and different bracketing structures, but none work.Thanks.
- The topic ‘Enable / Disable Gutenberg by Category’ is closed to new replies.