从自定义帖子类型编辑屏幕中删除标题 [英] Remove title from custom post type edit screen

查看:20
本文介绍了从自定义帖子类型编辑屏幕中删除标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I apply the remove_post_type_support('email_template', 'title'); only for post edit screen?

标题应该在创建时可用,而不是用于编辑.

The title should be available on create and not for edit.

推荐答案

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

In WordPress, there is one global variable to check on which screen we are and it is global $current_screen but problem is it can not be used with admin_init action.

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

So alternatively we can use load-(page) action to achieve it.

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' );
    }
}

你可以试一试.

如果您有任何疑问,请告诉我.

Let me know if you have any doubt.

已编辑

说明:如果您能在浏览器的 URL 栏上看到,那么您可以看到添加新帖子时它正在调用 post-new.php 以及您正在编辑时时间它用参数调用 post.php.

Explanation : If you can notice on the URL bar of the browser, then you can see when you are adding new post then it is calling post-new.php and when you are editing at that time it is calling post.php with parameters.

所以我们可以利用它来达到您想要的结果.

So we can utilize it to achieve your desired result.

这篇关于从自定义帖子类型编辑屏幕中删除标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆