I was wondering for CPT list and editing pages to show under Posts tab instead of creating its own tab. I really want to use CPT (over using categories) because I’d have control over capability and different templates. Any input is appreciated.
1 Answer
This can be done manipulating the global variable $submenu
. In this example, the post type name is portfolio
. See comments in code.
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;
}
Then, remove the menu item altogether:
add_action( 'admin_menu', 'remove_cpt_menu_wpse_98281', 15 );
function remove_cpt_menu_wpse_98281()
{
remove_menu_page( 'edit.php?post_type=portfolio' );
}
An in this example, we iterate through all post types that are public and not built-in and move the submenus inside the default Post post type.
And remove all menus with the same arguments.
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 );
}
}
Results in the following. I”d remove the “Add new” from all post types, as there’s already a shortcut in the main page of each: