add_submenu_page

Home » Functions » add_submenu_page

Add_submenu_page is a WordPress function that is used to add a submenu item under a custom post type or theme options menu in the WordPress admin dashboard. This function is particularly useful for developers who want to extend the functionality of WordPress by adding custom admin pages.

The add_submenu_page function takes five parameters:

  1. $parent_slug (required): The slug of the parent menu item under which the submenu item will be added.
  2. $page_title (required): The title of the submenu page.
  3. $menu_title (required): The title of the submenu item in the admin menu.
  4. $capability (required): The user capability required to access the submenu item.
  5. $menu_slug (required): The unique slug to identify the submenu page.

Example Usage code:

function my_submenu_page() { add_submenu_page( ‘edit.php?post_type=my_custom_post_type’, // Parent menu slug ‘My Submenu Page’, // Page title ‘My Submenu’, // Menu title ‘manage_options’, // Capability required ‘my_submenu_slug’, // Menu slug ‘my_submenu_callback’ // Callback function ); } add_action(‘admin_menu’, ‘my_submenu_page’);

In this example, we are adding a submenu page under the custom post type ‘my_custom_post_type’ with the title ‘My Submenu Page’. Only users with ‘manage_options’ capability will be able to access the page. The menu slug is set to ‘my_submenu_slug’, and the callback function ‘my_submenu_callback’ will be called when the submenu page is accessed.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.