我正在使用add_submenu_page向帖子类型添加子级菜单。
问题是子级菜单“批次”出现在帖子类型名称“离线课程”的顶部,但我希望它出现在底部
// Register Custom Post Type
function register_offline_course() {
$argscourse = array(
'label' => __( 'Offline Course', 'Offline Course' ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'revisions', ),
'taxonomies' => array( 'offline_course_cat' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'course_offline', $argscourse );
$argsbatch = array(
'label' => __( 'Batch', 'Batch' ),
'supports' => array( 'title','revisions', ),
'taxonomies' => array( 'offline_course_cat' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => false,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'course_batches', $argsbatch );
add_submenu_page( 'edit.php?post_type=course_offline', 'Batches', 'Batches',
'manage_options', 'edit.php?post_type=course_batches', NULL );
}
add_action( 'init', 'register_offline_course', 0 );
Run Code Online (Sandbox Code Playgroud)
请在自定义帖子类型函数之外创建 add_submenu_page 函数并调用 admin_menu 操作挂钩来创建子菜单,然后它就会起作用。
// Register Custom Post Type
function register_offline_course() {
$argscourse = array(
'label' => __( 'Offline Course', 'Offline Course' ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'revisions', ),
'taxonomies' => array( 'offline_course_cat' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'course_offline', $argscourse );
$argsbatch = array(
'label' => __( 'Batch', 'Batch' ),
'supports' => array( 'title','revisions', ),
'taxonomies' => array( 'offline_course_cat' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => false,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'course_batches', $argsbatch );
}
add_action( 'init', 'register_offline_course', 0 );
function sep1_menuexample_create_menu() {
//create a submenu under Settings
add_submenu_page( 'edit.php?post_type=course_offline', 'Batches', 'Batches',
'manage_options', 'edit.php?post_type=course_batches',NULL );}
add_action( 'admin_menu', 'sep1_menuexample_create_menu' );
Run Code Online (Sandbox Code Playgroud)