The get_admin_page_parent() WordPress PHP function retrieves the parent file of the current admin page.
Usage
$parent_page = get_admin_page_parent('example-submenu-page');
Parameters
- $parent_page (string) – Optional. The slug name for the parent menu (or the file name of a standard WordPress admin page). Default: ”.
More information
See WordPress Developer Resources: get_admin_page_parent()
Examples
Add a submenu page under the “Settings” menu
function my_plugin_menu() { add_submenu_page( 'options-general.php', 'My Plugin Settings', 'My Plugin', 'manage_options', 'my-plugin-settings', 'my_plugin_settings_page' ); } add_action('admin_menu', 'my_plugin_menu'); function my_plugin_settings_page() { $parent_page = get_admin_page_parent('my-plugin-settings'); echo 'The parent page is: ' . $parent_page; }
Add a submenu page under the “Posts” menu
function my_custom_submenu() { add_submenu_page( 'edit.php', 'My Custom Submenu', 'My Custom Submenu', 'manage_options', 'my-custom-submenu', 'display_custom_submenu' ); } add_action('admin_menu', 'my_custom_submenu'); function display_custom_submenu() { $parent_page = get_admin_page_parent('my-custom-submenu'); echo 'The parent page is: ' . $parent_page; }
Add a submenu page under the “Pages” menu
function my_page_submenu() { add_submenu_page( 'edit.php?post_type=page', 'My Page Submenu', 'My Page Submenu', 'manage_options', 'my-page-submenu', 'display_page_submenu' ); } add_action('admin_menu', 'my_page_submenu'); function display_page_submenu() { $parent_page = get_admin_page_parent('my-page-submenu'); echo 'The parent page is: ' . $parent_page; }
Add a submenu page under the “Appearance” menu
function my_theme_submenu() { add_submenu_page( 'themes.php', 'My Theme Submenu', 'My Theme Submenu', 'manage_options', 'my-theme-submenu', 'display_theme_submenu' ); } add_action('admin_menu', 'my_theme_submenu'); function display_theme_submenu() { $parent_page = get_admin_page_parent('my-theme-submenu'); echo 'The parent page is: ' . $parent_page; }
Add a submenu page under a custom top-level menu
function my_custom_menu() { add_menu_page( 'My Custom Menu', 'My Custom Menu', 'manage_options', 'my-custom-menu', 'display_custom_menu' ); add_submenu_page( 'my-custom-menu', 'My Custom Submenu', 'My Custom Submenu', 'manage_options', 'my-custom-submenu', 'display_custom_submenu' ); } add_action('admin_menu', 'my_custom_menu'); function display_custom_menu() { echo 'This is the main page of My Custom Menu.'; } function display_custom_submenu() { $parent_page = get_admin_page_parent('my-custom-submenu'); echo 'The parent page is: ' . $parent_page; }