可以使用 WordPress 过滤器简单地禁用编辑器。
WordPress 5 及更高版本
如果您只想为您自己的帖子类型禁用块编辑器,您可以将以下代码添加到您的插件或主题的functions.php 文件中。
add_filter('use_block_editor_for_post_type', 'prefix_disable_gutenberg', 10, 2);
function prefix_disable_gutenberg($current_status, $post_type)
{
// Use your post type key instead of 'product'
if ($post_type === 'product') return false;
return $current_status;
}
如果要完全禁用块编辑器(不推荐),可以使用以下代码。
add_filter('use_block_editor_for_post_type', '__return_false');
Gutenberg 插件(在 WordPress 5 之前)
如果您只想为您自己的帖子类型禁用古腾堡编辑器,您可以将以下代码添加到您的插件或主题的functions.php 文件中。
add_filter('gutenberg_can_edit_post_type', 'prefix_disable_gutenberg', 10, 2);
function prefix_disable_gutenberg($current_status, $post_type)
{
// Use your post type key instead of 'product'
if ($post_type === 'product') return false;
return $current_status;
}
如果您想完全禁用古腾堡编辑器(不推荐),您可以使用以下代码。
add_filter('gutenberg_can_edit_post_type', '__return_false');