devo devo - 4 years ago 128
PHP Question

Remove title from custom post type edit screen

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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download