Search code examples
wordpresswordpress-gutenberg

Restrict Gutenberg Editor for custom post type wordpress


I need to create my own custom post type and want to limit Gutenberg editor for my post type(only) and use WordPress editor in this post type. how can limit this plugin for my cpt??

thanks


Solution

  • You can use filter to disable Gutenberg for all post type with the exception of you custom post type name.

    /**
     * Disabling the Gutenberg editor all post types except post.
     *
     * @param bool   $can_edit  Whether to use the Gutenberg editor.
     * @param string $post_type Name of WordPress post type.
     * @return bool  $can_edit
     */
    function gutenberg_can_edit_post_type_83744857( $can_edit, $post_type ) {
        $gutenberg_supported_types = array( 'post' ); //Change this to you custom post type
        if ( ! in_array( $post_type, $gutenberg_supported_types, true ) ) {
            $can_edit = false;
        }
        return $can_edit;
    }
    add_filter( 'gutenberg_can_edit_post_type', 'gutenberg_can_edit_post_type_83744857', 10, 2 );