How to modify menu title of a plugin in wordpress?

2

I have a problem modifying the title of my plugin in the menu, I need the main title to be different from the second title, but I can not.

As in the image:

My Code:

public function menu(){
    add_menu_page('Gallery', __('Gallery', 'Galleries'), 'manage_options', 'gallery', array('view', 'main'));
    add_submenu_page( 'gallery', 'My Custom Page', 'My Custom Page', 'manage_options', 'my-top-level-slug');
    add_submenu_page( 'gallery', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-secondary-slug');
}
    
asked by anonymous 24.03.2014 / 21:23

2 answers

2

You can manipulate the global variable $submenu and change it there (we also have the variable $menu , but it has no use here):

add_action( 'admin_menu', function()
{
    add_menu_page(
        'Gallery', 
        __('Gallery', 'Galleries'), 
        'manage_options', 
        'gallery', 
        function(){ echo '<h1>Principal</h1>'; } 
    );
    add_submenu_page( 
        'gallery', 
        'My Custom Page', 
        'My Custom Page', 
        'manage_options', 
        'slug-1', 
        function(){ echo '<h2>Segundo</h2>'; }
    );
    add_submenu_page( 
        'gallery', 
        'My Custom Submenu Page', 
        'My Custom Submenu Page', 
        'manage_options', 
        'slug-2', 
        function(){ echo '<h2>Terceiro</h2>'; }
    );

    // Trocar o nome de um submenu
    global $submenu;
    $submenu['gallery'][0][0] = 'Galerias';
});

And here, a% w / w of the (summarized) variable:

Array (
    [index.php] => Array (
            [0] => Array (
                    [0] => Home
                    [1] => read
                    [2] => index.php
                )
            [10] => Array (
                    [0] => Updates <span class='update-plugins count-5' title='4 Plugin Updates, 1 Theme Update'><span class='update-count'>5</span></span>
                    [1] => update_core
                    [2] => update-core.php
                )
        )
    [edit.php] => Array ( [...etc...] )
    [upload.php] => Array ( [...etc...] )
    [edit.php?post_type=page] => Array ( [...etc...] )
    [edit-comments.php] => Array ( [...etc...] )
    [themes.php] => Array ( [...etc...] )
    [plugins.php] => Array ( [...etc...] )
    [users.php] => Array ( [...etc...] )
    [tools.php] => Array ( [...etc...] )
    [options-general.php] => Array ( [...etc...] )
    [gallery] => Array (
            [0] => Array (
                    [0] => Gallery
                    [1] => manage_options
                    [2] => gallery
                    [3] => Gallery
                    [4] => menu-top menu-icon-generic toplevel_page_gallery
                    [5] => toplevel_page_gallery
                    [6] => none
                )
            [1] => Array (
                    [0] => My Custom Page
                    [1] => manage_options
                    [2] => slug-1
                    [3] => My Custom Page
                )
            [2] => Array (
                    [0] => My Custom Submenu Page
                    [1] => manage_options
                    [2] => slug-2
                    [3] => My Custom Submenu Page
                )
        )
)
    
25.03.2014 / 13:17
1

When you use add_menu_page it automatically creates an item with the same name, you can use add_submenu_page and create an item called Galleries , and delete that gallery, the code looks something like this:

public function menu(){
    add_menu_page('Gallery', __('Gallery', 'Galleries'), 'manage_options', 'gallery', array('view', 'main'));
    add_submenu_page( 'gallery', 'Galleries', 'Galleries', 'manage_options', 'my-top-level-slug');
   remove_submenu_page('gallery','gallery');
}
    
24.03.2014 / 23:12