WordPress.org

Ready to get started?Download WordPress

Forums

How to remove upload/insert media button from Post but keep in Custom Post Type (6 posts)

  1. Ariful H Bhuiyan
    Member
    Posted 2 years ago #

    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

  2. brasofilo
    Member
    Posted 2 years ago #

    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');
  3. ewencameron1
    Member
    Posted 2 years ago #

    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

  4. brasofilo
    Member
    Posted 2 years ago #

    @ 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');
  5. ewencameron1
    Member
    Posted 2 years ago #

    That's Brilliant

    Thanks :D

  6. Ariful H Bhuiyan
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic