menu_page_url

Get the url to access a particular menu page based on the slug it was registered with.

Description

(string) menu_page_url( (string) $menu_slug, (constant) $echo = true ); 

If the slug hasn't been registered properly no url will be returned

Returns (string)

the url

Parameters (2)

0. $menu_slug (string)
The slug name to refer to this menu by (should be unique for this menu)
1. $echo — Optional. (constant) => true
Whether or not to echo the url - default is true

Usage

  1. if ( !function_exists( 'menu_page_url' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/plugin.php'; 
  3.  
  4. // The slug name to refer to this menu by (should be unique for this menu) 
  5. $menu_slug = ''; 
  6.  
  7. // Whether or not to echo the url - default is true 
  8. $echo = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = menu_page_url($menu_slug, $echo); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/plugin.php  
  1. function menu_page_url($menu_slug, $echo = true) { 
  2. global $_parent_pages; 
  3.  
  4. if ( isset( $_parent_pages[$menu_slug] ) ) { 
  5. $parent_slug = $_parent_pages[$menu_slug]; 
  6. if ( $parent_slug && ! isset( $_parent_pages[$parent_slug] ) ) { 
  7. $url = admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) ); 
  8. } else { 
  9. $url = admin_url( 'admin.php?page=' . $menu_slug ); 
  10. } else { 
  11. $url = ''; 
  12.  
  13. $url = esc_url($url); 
  14.  
  15. if ( $echo ) 
  16. echo $url; 
  17.  
  18. return $url;