9

How can I remove the Featured Image meta box? I've tried using the remove_meta_box function and specifying the boxes ID but it doesn't seem to work like it does for the other native meta boxes.

Here is the specific code I tried:

add_action( 'admin_menu', 'remove_thumbnail_box' );

function remove_thumbnail_box() {
    remove_meta_box( 'postimagediv', 'post', 'side' );
}

4 Answers 4

21

I haven't had time to test this but this looks like it should work for you.

add_action('do_meta_boxes', 'remove_thumbnail_box');

function remove_thumbnail_box() {
    remove_meta_box( 'postimagediv','post','side' );
}

Check this for more info.

Edit: The main change here is that you need to attach the function to do_meta_boxes instead of admin_menu

1
  • 1
    NOTE: You can also check the post type by looking at the variable passed to your callback (if you wanted to make this changes to set types), of course remembering to add the incoming var into the function, ie. function remove_thumbnail_box( $post_type )
    – t31os
    Commented Dec 6, 2010 at 22:57
6

The post thumbnail is added to a post type as something this post type supports. If you want to remove post thumbnail functionality from a post type, you can call remove_post_type_support(). Regular posts are also defined as custom post types, so it should work for them too.

add_action( 'init', 'wpse4936_init', 100 /* Something high, to make sure all post types are registered */ );
function wpse4936_init()
{
    remove_post_type_support( 'post', 'thumbnail' );
    // Or remove it for all registerd types
    foreach ( get_post_types() as $post_type ) {
        remove_post_type_support( $post_type, 'thumbnail' );
    }
}
7
  • Thanks Jan. Can you explain what add_action( 'init', 'wpse4936_init', 100 ); function wpse4936_init() { is all about? I've never seen anything like this.
    – matt
    Commented Dec 6, 2010 at 18:37
  • Also, I'm not actually trying to remove support of it, I'm must trying to remove the meta box (so I can add it in later into an existing custom meta box. I probably should have specified but I was trying to keep it simple.
    – matt
    Commented Dec 6, 2010 at 18:39
  • @matt: If you just want to remove the metaboxes then this is not what you want. The third parameter of add_action() defines the priority: the default is 10, so if you specify 100 it will run after all those of lower priority. You do this to make sure all custom post types are created (they usually are in the init hook), also those from other plugins.
    – Jan Fabry
    Commented Dec 6, 2010 at 22:13
  • @Jan, I was actually already aware of what the init and 100 were it's the wpse4936_init that I've never seen before. What is that?
    – matt
    Commented Dec 6, 2010 at 22:44
  • 3
    Just wanted to make a note that remove_post_type_support( $post_type, 'post-thumbnail' ); did not work for me. Looks like it works when written like this: remove_post_type_support( $post_type, 'thumbnail' );
    – RachieVee
    Commented Aug 24, 2017 at 19:38
0
add_action('do_meta_boxes', 'remove_thumbnail_box');
function remove_thumbnail_box($post_type) {
    remove_meta_box( 'postimagediv', 'post.php', 'side' );
}

Wordpress seems to only disable the featured images when calling action do_meta_boxes also use "post.php" as the post type instead of "post", I don't know why this is as it contradicts the documentation. Warning the do_meta_boxes seems to fire before function wp_get_current_user() becomes available so you won't be able to disable based on user type, it's all or nothing. Maybe someone else knows of a work around.

1
  • Can you also please explain the code as how it helps? Code without explanation is hard to understand and explaining the code is preferred.
    – bravokeyl
    Commented Jul 6, 2016 at 6:39
0

You can either remove it immediately after creating the custom post type or remove it later on using a hook like init.

Option #1: Remove it immediately after creating your custom post type:

$args = []; //your args here

register_post_type('my_post_type', $args);

remove_post_type_support('my_post_type', 'thumbnail');

Option #2: Remove it from an existing post type:

function remove_thumbnail_support()
{
    remove_post_type_support('my_post_type', 'thumbnail');
}

add_action('init', 'remove_thumbnail_support', 11);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.