从自定义 post 类型的编辑屏幕中删除标题

Remove title from custom post type edit screen

如何才能将 remove_post_type_support('email_template', 'title'); 应用到 post 编辑屏幕?

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

您需要在 function.php 文件中创建小函数:

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

希望对你有所帮助。

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

所以我们也可以使用 load-(page) 动作来实现它。

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 时它正在调用 post-new.php 并且当您当时正在编辑时,它正在调用带有参数的 post.php

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