对某些页面 ID 禁用古腾堡编辑器

ran*_*ank 3 wordpress wordpress-gutenberg

我需要在某些页面的编辑屏幕上禁用古腾堡编辑器。

我知道如何针对帖子类型禁用它,例如所有页面:

/************************************************************ */
/* 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;
}
Run Code Online (Sandbox Code Playgroud)

但我只想对某个页面禁用它,假设 ID 为“1716”。

如何以编程方式禁用某些页面 ID 的古腾堡编辑器?

Wil*_*ll. 5

用钩子就可以了use_block_editor_for_post

您可以通过多种方式使用钩子来完成此操作,但这里有一个示例;

使用您希望经典编辑器编辑的 post_ids 修改 excepted_ids 数组。(请记住,无论所有帖子类型如何,$post 都适用)

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 );
Run Code Online (Sandbox Code Playgroud)

请注意,您必须安装经典编辑器插件才能正常工作。