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' );
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
Method 2
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' );
}
}
Method 3
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.
Method 4
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);
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0