menu_page_url() WordPress Function

The menu_page_url() function is used to get the URL of a particular admin menu page. This is useful for creating links to specific admin pages from within your plugin or theme.

menu_page_url( string $menu_slug, bool $display = true ) #

Gets the URL to access a particular menu page based on the slug it was registered with.


Description

If the slug hasn’t been registered properly, no URL will be returned.


Top ↑

Parameters

$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 value: true


Top ↑

Return

(string) The menu page URL.


Top ↑

Source

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;
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.