admin管理员组文章数量:1287592
When you visit wp-admin/nav-menus.php
and there is no menu you get a set of metaboxes you cannot use. The only thing they do is drawing attention away from the Create Menu dialog.
I want to hide those boxes until there is a menu.
How can I do that?
When you visit wp-admin/nav-menus.php
and there is no menu you get a set of metaboxes you cannot use. The only thing they do is drawing attention away from the Create Menu dialog.
I want to hide those boxes until there is a menu.
How can I do that?
Share Improve this question asked Jan 2, 2013 at 8:30 fuxia♦fuxia 107k38 gold badges255 silver badges459 bronze badges1 Answer
Reset to default 5There are two important global variables in wp-admin/nav-menus.php
:
$nav_menus
is an array of all available menus, filled withwp_get_nav_menus()
.$wp_meta_boxes['nav-menus']
is an array of all available metaboxes for this screen.
We can hook into admin_head-nav-menus.php
, an action called after the first variable has been set up, and change the second variable:
add_action( 'admin_head-nav-menus.php', 't5_hide_dead_menu_metaboxes' );
/**
* Remove metaboxes for menu items when no menu exists.
*
* @wp-hook admin_head-nav-menus.php
* @return void
*/
function t5_hide_dead_menu_metaboxes()
{
empty ( $GLOBALS['nav_menus'] )
and $GLOBALS['wp_meta_boxes']['nav-menus'] = array ();
}
Download as plugin T5 Hide dead menu metaboxes from GitHub.
Additional Information:
After removing meta boxes the screen is looking a bit odd. We could change a bit initial hook and add some styles to make it looking better. So our hook could be:
/**
* Remove metaboxes for menu items when no menu exists.
*
* @wp-hook admin_head-nav-menus.php
* @return void
*/
function t5_hide_dead_menu_metaboxes()
{
if ( empty( $GLOBALS['nav_menus'] ) ) {
$GLOBALS['wp_meta_boxes']['nav-menus'] = array ();
echo '<style> #nav-menus-frame { margin-left: 0 !important; padding-top: 20px; } </style>';
}
}
Then the screen will look more natural:
本文标签: wp adminRemove unusable metaboxes in nav menu management screen
版权声明:本文标题:wp admin - Remove unusable metaboxes in nav menu management screen 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741314669a2371844.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论