Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I just want to make/add a Menu (Ads) that contains two submenus (View, Manage). My code is written below. The problem is that I don't know why it's popping another submenu in the main menu.

function Ad_menu() {
    // Main menu
    add_menu_page( 'Ads', 'Ads', 'manage_options', 'ad_menu', 'Main_Menu');

    // Submenus
    add_submenu_page( 'ad_menu', 'View', 'View', 'manage_options', 'View', 'View');
    add_submenu_page( 'ad_menu', 'Manage', 'Manage', 'manage_options', 'Manage', 'Manage');
}
add_action('admin_menu', 'Ad_menu');
share|improve this question
1  
Please use proper English, punctuation, readable code formatting etc. Questions are references to other users and people take their time to help you for free, so take the time to format your question as good as possible. –  kaiser Oct 18 '13 at 6:49
    
Try to give meaningful/unique names to each the slug and the callback: Function_Reference/add_submenu_page As you're using, it will only lead to confusion. –  brasofilo Oct 18 '13 at 8:15
add comment

1 Answer

The third menu item that appears (in fact, the first) is the main menu:

enter image description here

add_action('admin_menu', 'Ad_menu');

function Ad_menu()
{
    //Main menu
    add_menu_page( 
        'Ads page title', 
        'Ads menu title', 
        'manage_options', 
        'ad_menu_slug', 
        function(){ echo '<h1>Main menu</h1>'; }
    );
    //Submenus
    add_submenu_page( 
        'ad_menu_slug', 
        'View page title', 
        'View menu title', 
        'manage_options', 
        'ad_view_slug', // <-- Put main menu slug here
        function(){ echo '<h2>Views submenu</h2>'; }
    );
    add_submenu_page( 
        'ad_menu_slug', 
        'Manage page title', 
        'Manage menu title', 
        'manage_options', 
        'ad_manage_slug', 
        function(){ echo '<h2>Manage submenu</h2>'; }
    );
}

If you change the first submenu slug to ad_menu_slug (the main menu slug), the result will be this:

enter image description here

share|improve this answer
    
I have included my view and manage submenu pages on this menu page(Ads) through view and manage functions, but now they are showing up in the ads menu page. –  pd4627 Oct 18 '13 at 8:01
    
As I understand it, you don't want to join the 3 menus in 1, is it? So, why adding "manage" to the main menu? –  brasofilo Oct 18 '13 at 8:04
    
I want a main menu(ads) having 2 submenus(view & manage). Now i want to show my view & manage codes in different pages not in the main menu page. –  pd4627 Oct 18 '13 at 8:07
    
So what's the problem? You only have to change the Views submenu slug, as shown in the Answer. Leave "Manage" as it is. –  brasofilo Oct 18 '13 at 8:09
    
Ya that worked fine for me,thanks for that. But now my view and manage pages are shown on the same main menu page. –  pd4627 Oct 18 '13 at 8:11
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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