函数原型
menu_page_url( string $menu_slug, bool $display = true ): string
函数描述
Gets the URL to access a particular menu page based on the slug it was registered with.
是否弃用
未弃用
函数参数
-
$menu_slug
string
Required - The slug name to refer to this menu by (should be unique for this menu).
-
$display
bool
Optional - Whether or not to display the URL.
Default:
true
函数返回值
string The menu page URL.
函数位置
File: wp-admin/includes/plugin.php.
函数源码
function menu_page_url( $menu_slug, $display = true ) {
global $_parent_pages;
if ( isset( $_parent_pages[ $menu_slug ] ) ) {
$parent_slug = $_parent_pages[ $menu_slug ];
if ( $parent_slug && ! isset( $_parent_pages[ $parent_slug ] ) ) {
$url = admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) );
} else {
$url = admin_url( 'admin.php?page=' . $menu_slug );
}
} else {
$url = '';
}
$url = esc_url( $url );
if ( $display ) {
echo $url;
}
return $url;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |

