use_block_editor_for_post_type
Allows you to enable/disable content editing through Gutenberg (the WordPress block editor) for a post type.
WordPress 5.0 introduced the Gutenberg editor. use_block_editor_for_post_type( $post_type ) checks whether it is used for a specified post type. The use_block_editor_for_post_type hook fires at the end of this function and allows Gutenberg to be enabled or disabled for one post type or all post types at once.
The use_block_editor_for_post hook can override this hook and enable/disable Gutenberg for an individual post.
The Classic Editor plugin can also disable Gutenberg. Read more in a separate note.
Usage
add_filter( 'use_block_editor_for_post_type', 'wp_kama_use_block_editor_for_post_type_filter', 10, 2 );
/**
* Function for `use_block_editor_for_post_type` filter-hook.
*
* @param bool $use_block_editor Whether the post type can be edited or not.
* @param string $post_type The post type being checked.
*
* @return bool
*/
function wp_kama_use_block_editor_for_post_type_filter( $use_block_editor, $post_type ){
// filter...
return $use_block_editor;
}
- $use_block_editor(true/false)
- Whether to use the Gutenberg editor for the post type.
Default: true - $post_type(string)
- The post type being checked for block editor support.
Examples
#1 Completely disable Gutenberg on the site
This example disables Gutenberg for all post types on the site, completely disabling the new WordPress block editor.
add_filter( 'use_block_editor_for_post_type', '__return_false', 100 );
#2 Disable Gutenberg only for specified post types
Allow Gutenberg for the post post type and disable it for all other post types.
// Allow Gutenberg for the post post type.
add_filter( 'use_block_editor_for_post_type', function( $use, $post_type ){
return in_array( $post_type, [ 'post' ] );
}, 100, 2 );Changelog
| Since 5.0.0 | Introduced. |
Where the hook is called
return apply_filters( 'use_block_editor_for_post_type', true, $post_type );
Where the hook is used in WordPress
add_filter( 'use_block_editor_for_post_type', '_disable_block_editor_for_navigation_post_type', 10, 2 );