• Hello

    I am developing a theme where I am using a custom post type name ‘photo’. I Want too remove ‘Upload/Insert’ Media button from this custom post type but at the same time I want to keep it in Post.

    I found a code after searching where it remove the ‘Upload/Insert’ media button from both Custom Post type, Post and even from pages.

    add_action( 'media_buttons_context' , 'test' );
    function test() {
    	return;
    }

    Please help me to remove it only from the custom post type.

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • maybe there’s a more elegant way of doing this, but it works 🙂

    function check_post_type_and_remove_media_buttons() {
    	$post_id = !empty( $_GET['post'] ) ? (int) $_GET['post'] : 0;
            $post_type = get_post_type($post_id);
    	if( 'photo' == $post_type || 'photo' == $_GET['post_type']) {
    		add_action( 'media_buttons_context' , create_function('', 'return;') );
    	}
    }
    add_action('init','check_post_type_and_remove_media_buttons');

    Just saw you posted 4 mins ago and was looking for something very similar.

    Do you know how to remove the upload/insert buttons from the “posts” page, but still leave them on the “pages” pages please?

    Thanks

    @ ewencameron1,
    ok, and now elegant:

    function check_post_type_and_remove_media_buttons() {
    	global $current_screen;
            // use 'post', 'page' or 'custom-post-type-name'
    	if( 'post' == $current_screen->post_type ) add_action( 'media_buttons_context' , create_function('', 'return;') );
    }
    add_action('admin_head','check_post_type_and_remove_media_buttons');

    That’s Brilliant

    Thanks 😀

    Thread Starter Ariful H Bhuiyan

    (@arifulhb)

    Thanks for help.. 🙂 Though I didn’t get time to check but I’ll definitely replay how much it did help me.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to remove upload/insert media button from Post but keep in Custom Post Type’ is closed to new replies.