4

I'm developing a WordPress plugin and added add_menu_page() but not sure what is the use of first parameter $page_title. If this is to use to display page title on the plugin page then how can I do that?

<?php add_menu_page($page_title, $menu_title, $capability, $menu_slug); ?>

I have also gone through WordPress codex for this function but in example they are also using hard coded page title.

function register_my_custom_submenu_page() {
    add_submenu_page( 
        'tools.php', 
        'My Custom Submenu Page', 
        'My Custom Submenu Page', 
        'manage_options', 
        'my-custom-submenu-page', 
        'my_custom_submenu_page_callback' 
    );
}

function my_custom_submenu_page_callback() {
    echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>';
        echo '<h2>My Custom Submenu Page</h2>';
    echo '</div>'
}
  • I always thought that the $page_title parameter was to define what should be put in the <title> element, which the callback function has no control over. – shea Jun 2 '15 at 3:09
  • Me too :p ... that's why i shared it – Omer Jun 2 '15 at 3:42
4

Ok my bad found the answer on the codex page but at the very bottom so I'm adding this here as well so if anyone like my didn't catch it on WordPress's codex, they can find it here :)

Just use get_admin_page_title();

See the example 1 below:

function register_my_custom_submenu_page() {
    add_submenu_page( 
        'tools.php', 
        'My Custom Submenu Page', 
        'My Custom Submenu Page', 
        'manage_options', 
        'my-custom-submenu-page', 
        'my_custom_submenu_page_callback' 
    );
}

function my_custom_submenu_page_callback() {
    echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>';
        echo get_admin_page_title();
    echo '</div>';
}

And here is the example 2 below:

function register_my_custom_submenu_page() {
    add_submenu_page( 
        'tools.php', 
        'My Custom Submenu Page', 
        'My Custom Submenu Page', 
        'manage_options', 
        'my-custom-submenu-page', 
        'my_custom_submenu_page_callback' 
    );
}

function my_custom_submenu_page_callback() {
    global $title;
    echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>';
        echo $title;
    echo '</div>';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.