这可以通过操纵全局变量来完成$submenu
. 在本例中,帖子类型名称为portfolio
. 请参见代码中的注释。
add_filter( \'custom_menu_order\', \'move_one_post_type_wpse_98281\' );
function move_one_post_type_wpse_98281( $menu_ord )
{
global $submenu;
// Enable the next line to inspect the $submenu values
// echo \'<pre>\'.print_r($submenu,true).\'</pre>\';
// Iterate through all submenu items
foreach( $submenu[\'edit.php?post_type=portfolio\'] as $add_submenu )
{
// Move it inside the Post post type menu
$submenu[\'edit.php\'][] = $add_submenu;
}
return $menu_ord;
}
然后,完全删除菜单项:
add_action( \'admin_menu\', \'remove_cpt_menu_wpse_98281\', 15 );
function remove_cpt_menu_wpse_98281()
{
remove_menu_page( \'edit.php?post_type=portfolio\' );
}
在本例中,我们迭代
all post types 那是
public and not built-in 并将子菜单移到默认的Post Post类型中
并删除具有相同参数的所有菜单。
Please, use this with care. In case of doubts/problems, use a One-by-One approach using the code above.
add_filter( \'custom_menu_order\', \'move_all_post_types_wpse_98281\' );
add_action( \'admin_menu\', \'remove_all_cpt_menu_wpse_98281\', 15 );
function move_all_post_types_wpse_98281( $menu_ord )
{
global $submenu;
$args=array(
\'public\' => true,
\'_builtin\' => false
);
$post_types=get_post_types( $args );
// Iterate through all post types
foreach ($post_types as $post_type )
{
$cpt_submenu = \'edit.php?post_type=\' . $post_type;
foreach( $submenu[ $cpt_submenu ] as $add_submenu )
{
$submenu[\'edit.php\'][] = $add_submenu;
}
}
return $menu_ord;
}
function remove_all_cpt_menu_wpse_98281()
{
$args=array(
\'public\' => true,
\'_builtin\' => false
);
$post_types=get_post_types( $args );
foreach ($post_types as $post_type )
{
remove_menu_page( \'edit.php?post_type=\' . $post_type );
}
}
结果如下。我会从所有帖子类型中删除“添加新内容”,因为每个帖子的主页中都有一个快捷方式: