What is the use of $page_title and how to use it?

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>'
}

1 Answer
1

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>';
}

Leave a Comment