By adding post_type
to add_submenu_page
menu slug it will active CPT page menu. then you have to add parent page as that CPT to that commnet page by using submenu_file
filter.
# Move comment to CPT
function wpse354847_relocate_comments_in_admin_menu()
{
// Remove existing parent menu.
remove_menu_page( 'edit-comments.php' );
// Move Comments under Complaints ('complaint').
add_submenu_page(
'edit.php?post_type=complaint', //$parent_slug
__( 'Replies', 'wpse354847' ), //$page_title
__( 'Replies', 'wpse354847' ), //$menu_title
'edit_posts', //$capability
'edit-comments.php?post_type=complaint' //$menu_slug
);
}
add_action( 'admin_menu', 'wpse354847_relocate_comments_in_admin_menu' );
# add active page for parent page
add_filter('submenu_file', 'menuBold');
function menuBold($submenu_file)
{
global $pagenow;
if (( $pagenow == 'edit-comments.php' ) && ($_GET['post_type'] == 'complaint')) { // The address of the link to be highlighted
return 'edit-comments.php?post_type=complaint';
}
// Don't change anything
return $submenu_file;
}