除非我误解了这个问题,否则应该这样做:
add_action(\'admin_menu\', \'add_menu_pages\');
function add_menu_pages() {
add_menu_page(\'Menu Title\', \'Menu Title\', 10, \'main_menu\', \'submenu_1_callback\');
add_submenu_page(\'main_menu\', \'Sub Menu Title 1\', \'Sub Menu Title 1\', 10, \'main_menu\' , \'submenu_1_callback\');
add_submenu_page(\'main_menu\', \'Sub Menu Title 2\', \'Sub Menu Title 2\', 10, \'sub_menu\' , \'submenu_2_callback\');
}
function submenu_1_callback() {
echo "<h2>" . __( \'Toplevel & Sublevel 1\', \'menu-test\' ) . "</h2>";
}
function submenu_2_callback() {
echo "<h2>" . __( \'Sublevel 2\', \'menu-test\' ) . "</h2>";
}
编辑:
下面是隐藏第一个子菜单项的最简单方法。
1) 创建管理员。css并将其移动到/[模板目录]/css/
2) 将此添加到您的管理员。css:
#adminmenu li#toplevel_page_main_menu li.wp-first-item {
display: none !important;
}
3)向函数中添加以下代码。php
add_action(\'admin_enqueue_scripts\', \'custom_admin_css\');
function custom_admin_css() {
wp_enqueue_style( \'admin_css\', (get_template_directory_uri() . \'/css/admin.css\'), false, \'1.0.0\' );
}