这是我在项目中使用的一段工作代码。我将此代码放在“lib”文件夹中的一个文件中。您还可以写入函数文件。
$themename = "Ondeweb";
$shortname = "odwb";
$position = \'63.3\'; 
$file_dir=get_bloginfo(\'template_directory\');
$icon = $file_dir."/images/wand.png";
add_menu_page($themename, $themename, \'administrator\', \'ondeweb-now\', \'ondeweb_admin\', $icon, $position);
}
function innUbud_add_subpage() {
    add_submenu_page( 
        \'ondeweb-now\' 
        , \'Ads List\' 
        , \'Advertisement List\'
        , \'manage_options\'
        , \'ondeweb-now-advertise\'
        , \'advertiseList\'
    );
    add_submenu_page( 
        \'ondeweb-now\' 
        , \'Home page videos\' 
        , \'Home page videos\'
        , \'manage_options\'
        , \'ondeweb-now-videos\'
        , \'videoList\'
    );
}
function advertiseList() {  
    require_once( get_template_directory() . \'/lib/advertise.php\' );
}
function videoList() {  
    require_once( get_template_directory() . \'/lib/videos.php\' );
}
在上面的代码中,“ondeweb now”是父菜单的slug,它表示子菜单slug的父菜单(ondeweb now Advertised&ondeweb now videos)
详细说明如下:add_menu_page &;add_submenu_page