Skip to content

Instantly share code, notes, and snippets.

@mbijon
Last active July 10, 2023 23:30
Show Gist options
  • Save mbijon/7311081 to your computer and use it in GitHub Desktop.
Save mbijon/7311081 to your computer and use it in GitHub Desktop.
Remove 'Add Media' button from above WP editor, per post-type
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');
@gchtr
Copy link

gchtr commented Aug 27, 2018

I remove the media buttons by setting the media_buttons setting to false in the wp_editor_settings filter:

/**
 * Removes media buttons from post types.
 */
add_filter( 'wp_editor_settings', function( $settings ) {
    $current_screen = get_current_screen();

    // Post types for which the media buttons should be removed.
    $post_types = array( 'post' );

    // Bail out if media buttons should not be removed for the current post type.
    if ( ! $current_screen || ! in_array( $current_screen->post_type, $post_types, true ) ) {
        return $settings;
    }

    $settings['media_buttons'] = false;

    return $settings;
} );

@deadhead1971 You could add your own post types to the $post_types array if you want to have a check for more than one post type.

@andersonnarciso
Copy link

@gchtr thanks!

@jorellana818
Copy link

I remove the media buttons by setting the media_buttons setting to false in the wp_editor_settings filter:

/**
 * Removes media buttons from post types.
 */
add_filter( 'wp_editor_settings', function( $settings ) {
    $current_screen = get_current_screen();

    // Post types for which the media buttons should be removed.
    $post_types = array( 'post' );

    // Bail out if media buttons should not be removed for the current post type.
    if ( ! $current_screen || ! in_array( $current_screen->post_type, $post_types, true ) ) {
        return $settings;
    }

    $settings['media_buttons'] = false;

    return $settings;
} );

@deadhead1971 You could add your own post types to the $post_types array if you want to have a check for more than one post type.

This worked for me. Thank you!

@trublud
Copy link

trublud commented Jul 10, 2023

Here is another way
$settings = array('textarea_name'=>'Overview[Notes]') ;
$settings['media_buttons'] = false;
wp_editor( htmlspecialchars_decode($text), 'mettaabox_ID2', $settings );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment