Using WordPress ‘get_admin_page_title()’ PHP function

The get_admin_page_title() WordPress PHP function retrieves the title of the current admin page.

Usage

echo esc_html( get_admin_page_title() );

Parameters

  • None

More information

See WordPress Developer Resources: get_admin_page_title()

Examples

Display Admin Page Title in a Custom Admin Menu Page

In this example, we create a custom admin menu page and display the admin page title using get_admin_page_title().

function my_custom_admin_menu() {
  add_menu_page(
    'My Custom Page', // Page title
    'My Custom Page', // Menu title
    'manage_options',  // Capability
    'my-custom-page',  // Menu slug
    'my_custom_page_content' // Callback function
  );
}
add_action('admin_menu', 'my_custom_admin_menu');

function my_custom_page_content() {
  ?>
  <div class="wrap">
    <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
    <p>Welcome to my custom admin page!</p>
  </div>
  <?php
}

Add a Custom Submenu Page

In this example, we create a custom submenu page and display the admin page title using get_admin_page_title().

function my_custom_submenu() {
  add_submenu_page(
    'my-custom-page', // Parent menu slug
    'My Custom Submenu', // Page title
    'My Custom Submenu', // Menu title
    'manage_options', // Capability
    'my-custom-submenu', // Menu slug
    'my_custom_submenu_content' // Callback function
  );
}
add_action('admin_menu', 'my_custom_submenu');

function my_custom_submenu_content() {
  ?>
  <div class="wrap">
    <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
    <p>Welcome to my custom submenu page!</p>
  </div>
  <?php
}

Display Admin Page Title in a Custom Admin Settings Page

In this example, we create a custom admin settings page and display the admin page title using get_admin_page_title().

function my_custom_settings() {
  add_options_page(
    'My Custom Settings', // Page title
    'My Custom Settings', // Menu title
    'manage_options', // Capability
    'my-custom-settings', // Menu slug
    'my_custom_settings_content' // Callback function
  );
}
add_action('admin_menu', 'my_custom_settings');

function my_custom_settings_content() {
  ?>
  <div class="wrap">
    <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
    <p>Adjust your custom settings below:</p>
  </div>
  <?php
}