Enable Gutenberg editor for post types

We’ve all seen and heard about the Gutenberg editor in WordPress now, and it’s not going anywhere (as much as some people wish that it would). Even though this is now the default editor in WordPress there’s still some post types that aren’t set up to use it. Normally that’s not to much of a big deal, but if you want to have the Gutenberg editor on your post types, here’s how!

Custom Post Types

Enabling the Gutenberg editor on your own custom post types is easy to do. It’s all part of the post type registraiton!

register_post_type ('my_post_type', array (
    'label' => 'My Custom Post Type',
    'public' => true,
    'show_in_rest' => true,
));

That’s all there is to it! As long as your post type is public and had ‘show_in_rest’ enabled, you’ll be using Gutenberg to edit it’s content.

WooCommerce Products

This is a strange one. WooCommerce products don’t use the Gutenberg editor, which sounds… crazy… to me. Product listings are one of the biggest use-cases for the sort of visual block-based editing that Gutenberg enables, so not having it available doesn’t make sense.

Because the product post type is already set, it needs a slightly different approach.

function enable_gutenberg_for_post_types ($use_editor, $post_type) {
    $post_types = array (
        'product'
    );

    if (in_array ($post_type, $post_types)) {
        $use_editor = true;
    } // if ()

    return $use_editor;
}

add_filter ('use_block_editor_for_post_type', 'enable_gutenberg_for_post_types');

Also be aware that this can work for any other post type as well, so you can add in more post types then just product.

That is all there is to it, but if you have any other tips or tricks, please leave a message below!

Leave a Reply

Your email address will not be published. Required fields are marked *