How to remove a metabox from menu editor page?

By inspecting the file /wp-admin/nav-menus.php we can see that these meta-boxes:

metaboxes

are rendered with:

<?php do_meta_boxes( 'nav-menus', 'side', null ); ?>

The file /wp-admin/includes/nav-menu.php contains the corresponding add_meta_box() calls and from that we can construct the relevant removal code:

function custom_remove() {      
    remove_meta_box('nav-menu-theme-locations', 'nav-menus', 'side'); 
    remove_meta_box('add-custom-links', 'nav-menus', 'side'); 
    remove_meta_box('add-post', 'nav-menus', 'side'); 
    remove_meta_box('add-page', 'nav-menus', 'side'); 
    remove_meta_box('add-category', 'nav-menus', 'side'); 
}
add_action('admin_head-nav-menus.php', 'custom_remove');

where we can use for example the admin_head-nav-menus.php action since it is called before these meta-boxes are rendered.

If you have a custom post type (or a custom taxonomy) then you can remove it’s meta-box with

   remove_meta_box( 'add-xxx' , 'nav-menus' , 'side' ); 

where xxx is the corresponding name.

You can further check out the functions wp_nav_menu_setup(), wp_nav_menu_post_type_meta_boxes() and wp_nav_menu_taxonomy_meta_boxes() to see how the meta-boxes are added.

Leave a Comment

tech