• 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.

    • This topic was modified 1 year, 6 months ago by phil2016.
    • This topic was modified 1 year, 6 months ago by phil2016. Reason: Clarity and grammar
    • This topic was modified 1 year, 6 months ago by bcworkz. Reason: code format partly fixed
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    The 5 in add_filter('use_block_editor_for_post', '__return_false', 5); has nothing to do with WP version. It manages in what order callbacks are executed. Unverified, but anything < 10 will likely be adequate. (10 is the default)

    Should work:
    if (has_category(['2007','2022',])) return true;
    assuming 2007 and 2022 are the slug names for your category terms.

    You could just let authors select which editor to use in each case. There’s a setting in the classic editor plugin that allows this. Whichever editor was used last to save a post is retained and indicated in the post list table. It acts as a strong suggestion on which editor one should use for every post.

    Of course this means someone could use the “wrong” editor. In theory it shouldn’t matter if one did, but freely switching back and forth is admittedly far from ideal. It’s typically fairly obvious when one uses the wrong editor and that one should switch to the other. So using the right editor does take a small amount of discipline, but it saves you from needing additional code you’d be responsible for maintaining.

    Thread Starter phil2016

    (@phil2016)

    @bcworkz Thank you very much!

    I had no idea I could do that with the Classic Editor plugin. I’ve been messing around for hours trying to make that script work and all the time I had a plugin that could do it. Thank you.

    Now, just from curiosity — is that the ‘best’ plugin to do this job? I know there are others, but I just tend to stick with what’s already there, but I thought I’d ask. Thanks again for your help.

    Moderator bcworkz

    (@bcworkz)

    If you like the “classic” tinyMCE editor, the related classic plugin IMO is the way to go. I’m unaware of alternatives for tinyMCE style editing, but maybe I haven’t been paying attention. There are many other page builder plugins available. My issue with most of them is you become locked into using them. Remove the plugin and the pages built with them cease to display correctly. The default block (Gutenberg) editor is partly excepted. Basic post content will still display correctly without the block editor, if content were exported elsewhere for example.

    Page builders do offer many features that will help you build more immersive content, all in one package. Elements that are not readily available with the classic editor. If you want the more elaborate elements, you’d either need to develop them for yourself or utilize a separate plugin which offers such features.

    As mentioned, you can freely switch between classic and block editor. I’m not so sure how easily you can switch between classic and other page builders. It may be possible, I’ve never tried to do so.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Enable / Disable Gutenberg by Category’ is closed to new replies.