Reputation: 435
I would like to know what the usage of $page_title in function add_menu_page or add_submenu_page because I don't see it in the menu / sub menu page. To have the title, I have to manually code the plugin, such as :
<div class="wrap">
<h2>Page Title</h2>
....
Here is the code for creating menu / sub menu :
add_menu_page(
'Menu Page Title',
'Menu Title',
'publish_posts',
'otto-ext' );
add_submenu_page(
'otto-ext',
'Sub Menu Page Title',
'Sub Menu Title',
'publish_posts',
'location-ext',
'custom_menu' );
Is it possible to display "Menu Page Title" or "Sub Menu Page Title" automatically?
Thanks in advance
Upvotes: 1
Views: 4412
Reputation: 51
I know I'm two years late to the party, but for those still landing on this page:
You can use get_admin_page_title()
, which has been available since 2.5. Alternatively, you can just use $GLOBALS['title']
, which WordPress sets as soon as admin-header.php is loaded.
<div class="wrap">
<h2><?php echo $GLOBALS['title'] ?></h2>
<!-- ... -->
</div>
Upvotes: 5
Reputation: 11799
Here is an example of a menu and sub-menu using scripts:
add_action( 'admin_menu', 'MyPluginMenu' );
function MyPluginMenu() {
$SettingsPath = 'path_to_plugin/menu_script.php';
add_menu_page( 'PageTitle', 'MenuTitle', 'administrator', $SettingsPath, '', plugins_url( 'path_to_plugin/images/plugin_icon.png' ) );
add_submenu_page( $SettingsPath, 'PageTitle', 'SubMenuTitle', 'administrator', 'path_to_plugin/sub_menu_script.php', '' );
}
This will work for PLUGINS as you mentioned in your question I have to manually code the plugin, such as:
.
Upvotes: 1
Reputation: 10607
You are correct. You will have to code the title manually. The $page_title
parameter is only for the title tag in the head section of the HTML document, <title>$page_title</title>
, which is used as the "name" of the tab in your browser.
There is no way to use the parameters given to add_menu_page inside the function that echoes the content of the page you're creating. So no, there is no easy way to generate page titles automatically from that information.
Upvotes: 2