Main menu link also showing on submenu in WP admin panel

后端 未结 1 1423
日久生厌
日久生厌 2021-01-21 04:30

I have created a custom top menu in admin panel and also add two submenu for that menu. my code is as follows:

add_action(\'admin_menu\', \'my_create_menu\');

f         


        
相关标签:
1条回答
  • 2021-01-21 04:44

    You can achieve this by giving the top-level page (the add_menu_page() call) the same slug as the first submenu page. Then reference this slug in the first parameter of both add_submenu_page() calls.

    Here's the code:

    add_menu_page( 
        'My custom menu Settings', 
        'My custom menu Settings', 
        'manage_options', 
        'sub-suge', 
        'my_custom_menu', 
        plugins_url( 'assets/images/test.png', __FILE__ ) 
    );
    
    add_submenu_page( 
        'sub-suge' , 
        'My custom submenu-1', 
        'My custom submenu-1', 
        'manage_options', 
        'sub-suge', 
        'my_custom_submenu_1' 
    );
    
    add_submenu_page( 
        'sub-suge' , 
        'My custom submenu-2', 
        'My custom submenu-2', 
        'manage_options', 
        'sub-page', 
        'my_custom_submenu_2' 
    );
    
    0 讨论(0)
提交回复
热议问题