To remove a metabox from all post types at once, using a foreach seems like the logical thing to do. However it doesn’t always work and I don’t understand why.

For examlple viewing the “Post” post type the following only removes the trackbacksdiv :

function remove_metabox_from_all_post_types() {
$post_types = get_post_types();
foreach ( $post_types as $post_type )
            remove_meta_box('trackbacksdiv', $post_type, 'normal');
            remove_meta_box('postcustom', $post_type, 'normal');
            remove_meta_box('authordiv', $post_type, 'normal');
            remove_meta_box('postexcerpt', $post_type, 'normal');
}
add_action('admin_menu', 'remove_metabox_from_all_post_types', 999);

While this removes all of them when viewing the “Post” post type:

function remove_metabox_from_all_post_types() {
$post_types = get_post_types();
foreach ( $post_types as $post_type )
            remove_meta_box('trackbacksdiv', 'post', 'normal');
            remove_meta_box('postcustom', 'post', 'normal');
            remove_meta_box('authordiv', 'post', 'normal');
            remove_meta_box('postexcerpt', 'post', 'normal');
}
add_action('admin_menu', 'remove_metabox_from_all_post_types', 999);

I would think that get_post_types is fired after the metaboxes are registered, but that’s the only reason I can guess it’s not working the first way, unless it’s a careless syntax error that I’m not picking up. I tried using the do_metaboxes actions hook as well but it didn’t make a difference.

Any ideas?

Read more here: remove_meta_box for all post types doesn’t seem to work


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , ,

Wordpress related questions and answers: