use_block_editor_for_post
Allows you to enable or disable Gutenberg (the WordPress block editor) for an individual post.
There is a similar use_block_editor_for_post_type hook that enables or disables the block editor for a post type as a whole. This hook runs later and affects an individual post.
You can also use the Classic Editor plugin to disable Gutenberg. Read more in a separate note.
Usage
add_filter( 'use_block_editor_for_post', 'wp_kama_use_block_editor_for_post_filter', 10, 2 );
/**
* Function for `use_block_editor_for_post` filter-hook.
*
* @param bool $use_block_editor Whether the post can be edited or not.
* @param WP_Post $post The post being checked.
*
* @return bool
*/
function wp_kama_use_block_editor_for_post_filter( $use_block_editor, $post ){
// filter...
return $use_block_editor;
}
- $use_block_editor(true/false)
- Whether to use the Gutenberg editor for an individual post.
- $post(WP_Post)
- The post being checked.
Examples
#1 Disable the Gutenberg editor for the post with ID = 10
add_filter( 'use_block_editor_for_post', 'disable_gutenberg_for_post', 10, 2 );
function disable_gutenberg_for_post( $use, $post ){
if( $post->ID == 10 )
return false;
return $use;
}Changelog
| Since 5.0.0 | Introduced. |
Where the hook is called
use_block_editor_for_post
wp-includes/post.php 8798
return apply_filters( 'use_block_editor_for_post', $use_block_editor, $post );