Remove title from custom post type edit screen

孤街浪徒 提交于 2019-12-11 10:19:55

问题


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.


回答1:


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.

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

You can try it and give it a go.

Let me know if you have any doubt.

Edited

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.




回答2:


You need to make small function in your function.php file:

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

I hope, It'll be help.



来源:https://stackoverflow.com/questions/34562995/remove-title-from-custom-post-type-edit-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!