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
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 );
You can do this by plugin or custom code.
Plugin Disable Gutenberg
Code, add it to functions.php
function mh_disable_gutenberg($is_enabled, $post_type) { if ($post_type === 'news') return false; // change news to your post type return $is_enabled; } add_filter('gutenberg_can_edit_post_type', 'mh_disable_gutenberg', 10, 2);
For those finding this question after WordPress 5.0 was released, you can turn off the Block Editor (f.k.a Gutenberg) for certain post types by using the use_block_editor_for_post_type filter like so:
add_filter('use_block_editor_for_post_type', function( $useBlockEditor, $postType ){
if( $postType == 'your-custom-post-type-slug' )
return false;
return $useBlockEditor;
}, 10, 2);