Closed henrywright closed 10 years ago
You can add an action on add_meta_boxes
with a lower priority than the default (10) that does the conditional check for those pages and then runs remove_meta_box()
with the appropriate paramaters based on your thumbnail registration settings.
Something like this based on your code above:
add_action( 'add_meta_boxes', function() {
if ( [check for condition you want to remove the meta box on] ) {
remove_meta_box( 'featured-image-2-page', 'page', 'normal' );
}
}, 20);
@chrisscott neat solution, very much appreciated.
I just tested the solution, it doesn't seem to work, even without the condition. I even tried various IDs such as featured-image-2-page
, page-featured-image-2
and featured-image-2
Any ideas why this might not be working?
Sorry, I misread the registration and the remove function.. It should be:
remove_meta_box( 'page-featured-image-2', 'page', 'side' );
Ah yes, the third argument should be 'side'. All works now, thanks again.
Here's my full function:
function my_remove_meta_boxes() {
$screen = get_current_screen();
if ( is_admin() && ( $screen->id == 'page' ) ) {
global $post;
if ( $post->ID == $id ) {
remove_meta_box( 'page-featured-image-2', 'page', 'side' );
}
}
}
add_action( 'add_meta_boxes', 'my_remove_meta_boxes', 20 );
Where $id
is the ID of the page you'd like to exclude the meta box from.
This metabox now appears on all page admin screens. Is there a way to output the metabox by page slug or by page ID? For example, I'd like the metabox to show up on my 'about-me' admin page but not on my 'contact-me' admin page.