描述
如果未正确注册slug,则不会返回URL。
参数
- $menu_slug
-
(string)(必填) 用于引用此菜单的slug名称(对于此菜单应是唯一的)。
- $display
-
(bool)(可选) 是否显示URL。
默认值: true
返回
(string) 菜单页面URL。
源码
更新日志
版本 | 描述 |
---|---|
3.0.0 | 开始引入 |
使用示例
我们可以使用此函数在现有父菜单下添加子菜单。
// check if parent admin page exist or not. $main_menu = menu_page_url('PARENT-PAGE-SLUG', false); if ($main_menu) { // The top menu exists, so add a sub-menu item. add_submenu_page( 'PARENT-PAGE-SLUG', esc_html__( 'Sub-Menu Page Title', 'myplugin' ), // page Title esc_html__( 'Sub-Menu Page', 'myplugin' ), // menu link text 'manage_options', // capability to access the page 'submenu-page-slug', // page URL slug 'submenu_page_content_callback', // callback function with content 2 // priority ); } else { // No top menu with that slug, we can create it. add_menu_page( esc_html__( 'Parent Page Title', 'myplugin' ), // page Title esc_html__( 'Parent Page', 'myplugin' ), // menu link text 'manage_options', // capability to access the page 'parent-page-slug', // page URL slug 'parent_menu_page_content_callback', // callback function with content ); }