1

In my custom plugin subapges i want to echo their titles specifed in add_submenu_page() but i don't know how do that.

This is part of code of my plugin which display links in left-side menu:

add_menu_page('Title', 'Title', 'manage_options', 'my-parent', 'my_page', 'dashicons-clipboard');
add_submenu_page( 'my-parent', 'Main title', 'Main title', 'manage_options', 'my_page');
add_submenu_page( 'my-parent', 'Subpage title', 'Subpage title', 'manage_options', 'my_subpage', 'subpage-handle');

What i must echo of each subpage between <?php ... ?> to display titles specifed above?

And why links from left-side menu are not higlithed when im at current subpage? I got other plugins and when i go to the his subpage links are higlited in menu.

0

In the function add_submenu_page() you have to specify a callback function at the end. Like you did it in the 2nd submenu page. You have to add this function to your code!

Example:

add_submenu_page( 'my-parent', 'Subpage title', 'Subpage title', 'manage_options', 'my_subpage', 'subpage-handle');

function subpage-handle()
{
    echo '<h1>Subpage title</h1>';
}

In this function you can echo whatever you want. I also reproduced your highlight behavior. It seems everything works fine.

Full example:

function add_menu() {
    add_menu_page('Title', 'Title', 'manage_options', 'my-parent', 'my_page', 'dashicons-clipboard');
    add_submenu_page( 'my-parent', 'Main title', 'Main title', 'manage_options', 'my-subpage', 'my_1st_subpage');
    add_submenu_page( 'my-parent', 'Subpage title', 'Subpage title', 'manage_options', 'my-subpage-2', 'my_2nd_subpage');
}

function my_page()
{
    echo '<h1>Title</h1>';
}

function my_1st_subpage()
{
    echo '<h1>Main title</h1>';
}

function my_2nd_subpage()
{
    echo '<h1>Subpage title</h1>';
}

add_action('admin_menu', 'add_menu');

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.