WordPress 在其第五版中添加了古腾堡/ block 编辑器,并且默认情况下为帖子和页面帖子类型启用。
在不久的将来,它可能会默认为所有自定义帖子类型启用,因此作为 WordPress 开发人员,我想知道如何为我自己的自定义帖子类型禁用此编辑器?我想为我从插件或主题注册的帖子类型保留经典编辑器。
最佳答案
可以使用 WordPress 过滤器简单地禁用编辑器。
WordPress 5 及更高版本
如果您只想为自己的帖子类型禁用 block 编辑器,您可以将以下代码添加到您的插件或主题的 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;
}
如果您想完全禁用 block 编辑器(不推荐),您可以使用以下代码。
add_filter('use_block_editor_for_post_type', '__return_false');
古腾堡插件(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');
关于php - 如何禁用某些帖子类型的古腾堡/ block 编辑器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52199629/