Using WordPress ‘add_management_page()’ PHP function

The add_management_page() WordPress PHP function adds a submenu page to the ‘Tools’ main menu in the WordPress dashboard.

Usage

add_management_page( 'Page Title', 'Menu Title', 'User Capability', 'Menu Slug', 'Output Function', 'Menu Position');

In this example, ‘Page Title’ is what appears in the title tags when the menu is selected, ‘Menu Title’ is the name of the menu, ‘User Capability’ determines who can see this menu, ‘Menu Slug’ is the unique identifier for this menu, ‘Output Function’ is the function to display the content for this page, and ‘Menu Position’ is the order of this item in the menu.

Parameters

  • $page_title (string) – The text to be displayed in the title tags of the page when the menu is selected.
  • $menu_title (string) – The text to be used for the menu.
  • $capability (string) – The capability required for this menu to be displayed to the user.
  • $menu_slug (string) – The unique slug name for this menu.
  • $callback (callable, optional) – The function to be called to output the content for this page. Default is ” (empty string).
  • $position (int, optional) – The position in the menu order this item should appear. Default is null.

More information

See WordPress Developer Resources: add_management_page()
The function is included in WordPress since version 2.0.0.

Examples

Basic Page Addition

function setup_tool_submenu(){
  add_management_page('My New Page', 'My New Menu', 'manage_options', 'my_new_menu', 'display_my_page_content');
}
add_action('admin_menu', 'setup_tool_submenu');

function display_my_page_content(){
  echo 'Welcome to My New Page!';
}

In this example, we add a new submenu page to the ‘Tools’ menu in the WordPress dashboard. The page is titled ‘My New Page’, and the menu is titled ‘My New Menu’. The ‘display_my_page_content’ function is used to display the content of the page when the menu item is clicked.

Specifying Menu Position

function setup_tool_submenu(){
  add_management_page('My New Page', 'My New Menu', 'manage_options', 'my_new_menu', 'display_my_page_content', 2);
}
add_action('admin_menu', 'setup_tool_submenu');

function display_my_page_content(){
  echo 'Welcome to My New Page!';
}

Similar to the first example, but now we specify that our menu item should appear as the second item in the ‘Tools’ menu.

Different Capability Requirement

function setup_tool_submenu(){
  add_management_page('My New Page', 'My New Menu', 'edit_posts', 'my_new_menu', 'display_my_page_content');
}
add_action('admin_menu', 'setup_tool_submenu');

function display_my_page_content(){
  echo 'Welcome to My New Page!';
}

This example shows how to create a menu item that will only be visible to users with the ‘edit_posts’ capability.