Support » Fixing WordPress » [Plugin] Getting an extra sub menu item in my plugin menu

  • I’m having a weird problem with a menu I’m adding to the administration interface.

    I keep getting an unwanted sub menu item.
    I have the follwoing code:

    add_action('admin_menu', 'sl_menu');
    function sl_menu()
      if (function_exists('add_menu_page')) {
    		add_menu_page('Menu title','Menu title', 'manage_options', 'my-pluging-folder/my_plugin.php', '', '');
    	if (function_exists('add_submenu_page')) {
    		add_submenu_page('my-pluging-folder/my_plugin.php', 'Sub menu title', 'Sub menu title', 'manage_options', 'my-pluging-folder/some_file.php');

    The result is:
    Menu Tile
    – Menu Title
    – Sub menu title

    As you can see, the main page / menu tile is also shown as a sub menu item.

    Why is that?

    If I take “the same” code from Lester Chans plugin ‘wp-polls’, I only get the main menu item + one sub menu item:

    ### Function: Poll Administration Menu
    add_action('admin_menu', 'poll_menu');
    function poll_menu() {
    	if (function_exists('add_menu_page')) {
    		add_menu_page(__('Polls', 'wp-polls'), __('Polls', 'wp-polls'), 'manage_polls', 'wp-polls/polls-manager.php', '', plugins_url('wp-polls/images/poll.png'));
    	if (function_exists('add_submenu_page')) {
    		add_submenu_page('wp-polls/polls-manager.php', __('Manage Polls', 'wp-polls'), __('Manage Polls', 'wp-polls'), 'manage_polls', 'wp-polls/polls-manager.php');

    Now, why does this work?

Viewing 5 replies - 1 through 5 (of 5 total)
  • *bump*



    Search before you post! This is a very common problem. Could have saved yourself 2 weeks if you had done a quick search on these forums!

    If this forum had a good search engine, I would probably have found the solution long time ago. Posting here is alwyas my last resort.

    Thanks for the link.

    So the solution from the link is:


    add_menu_page('Section', 'Section', 10, __FILE__, 'section');
    add_submenu_page(__FILE__, 'Edit', 'Edit', 10, 'section-edit', 'section_edit');


    add_menu_page('Section', 'Section', 10, __FILE__, 'section');
    add_submenu_page(__FILE__, 'Edit', 'Edit', 10, __FILE__, 'section_edit');



    I got the same problem before.You may take a look at this submenu sample for a solution.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin] Getting an extra sub menu item in my plugin menu’ is closed to new replies.