I need to disable the gutenberg editor on the edit screen of certain pages.
I know how to disable it for post types, like all pages:
/************************************************************ */
/* Disable Gutenberg for post type */
add_filter('use_block_editor_for_post_type', 'prefix_disable_gutenberg', 10, 2);
function prefix_disable_gutenberg($current_status, $post_type)
{
if ( $post_type == 'page' ) return false;
return $current_status;
}
But I only want to disable it for a page, let's say with the ID of "1716".
How can I disable the gutenberg editor for certain page IDs programmatically?
It's possible with the use_block_editor_for_post
hook.
You can do it a variety of ways then with the hook, but here's one example;
modify the excluded_ids array with post_ids that you want edited by the classic-editor.(remember $post is applicable regardless across all post types)
function disable_block_editor_for_page_ids( $use_block_editor, $post ) {
$excluded_ids = array( 2374, 5378, 21091);
if ( in_array( $post->ID, $excluded_ids ) ) {
return false;
}
return $use_block_editor;
}
add_filter( 'use_block_editor_for_post', 'disable_block_editor_for_page_ids', 10, 2 );
Note that you must have the classic-editor plugin installed for this to work.