0

I've tried to use

function my_remove_meta_boxes() {
    remove_meta_box( 'postimagediv', 'post', 'side' );
}
add_action( 'add_meta_boxes', 'my_remove_meta_boxes' );

and

function hide_featured_image( $hidden, $screen) {

    $hidden[] = 'postimagediv';
    return $hidden;

} 
add_filter('hidden_meta_boxes', 'hide_featured_image', 10, 2);

I've also tried it with default_hidden_meta_boxes filter.

None of these work.

I don't even know if I'm using the correct name for the box because I can't get it to print out the names of the default boxes.

I'm using WordPress 5.2.1 with Gutenberg and Nelio Content plugin which has its own featured image sidebar box. I want to hide the default Featured Image so the admins don't use it by mistake.

2 Answers 2

3

I tested it myself with the code you use and it only works with Gutenburg disabled. It seems to be related to the new editor.

Assuming you want to use the new editor, and depending on your theme and plugins this code may work for you (it worked from my tests):

add_action( 'after_setup_theme', function(){
    // this removes the feature image panel from all your post types 
    // including 'post'
    remove_theme_support( 'post-thumbnails' );
    // include all post-types that use the featured image panel here
    add_theme_support( 'post-thumbnails', array( 'example-post-type' ) ); 

}, 11 );
0

First grab the tag ID of the metabox (e.g: postimagediv) And you can do it with CSS:

if($condition):
//Hide Metabox (Feature Image Box) with CSS
echo '<style>#postimagediv{display:none;}</style>';
endif;

OR with JS:

if($condition):
//Hide Metabox (Feature Image Box) with JS
echo '<script type="text/javascript">jQuery('#postimagediv').remove();</script>';
//or you could use .hide();
endif;

Must be added within the admin environment PHP file

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.