从自定义文章类型编辑屏幕中删除标题


Remove title from custom post type edit screen

如何仅将remove_post_type_support('email_template', 'title');应用于编辑后屏幕?

标题应在创建时可用,而不可编辑。

在WordPress中,有一个全局变量可以检查我们在哪个屏幕上,它是global $current_screen,但问题是它不能与admin_init操作一起使用。

因此,我们可以使用加载(页面)操作来实现它

add_action( 'load-post.php', 'remove_post_type_edit_screen', 10 );
function remove_post_type_edit_screen() {
    global $typenow;
    if($typenow && $typenow === 'email_template'){
        remove_post_type_support( 'email_template', 'title' );
    }
}

你可以试一试。

如果你有任何疑问,请告诉我。

已编辑

说明:如果你能在浏览器的URL栏上注意到,那么你可以看到当你添加新帖子时,它会调用post-new.php,而当你编辑时,它则会用参数调用post.php

因此,我们可以利用它来实现您想要的结果。

您需要在function.php文件中生成一个小函数:

add_action('admin_init', 'email_template_hide_title');
function email_template_hide_title() {
     remove_post_type_support('email_template', 'title');
}

我希望,这会有所帮助。