• I’m working on a plugin and I’ve created a new top-level menu. The top-level menu is called ‘XML Editor’. My code creates this just fine. The problem is that there is also a sub-menu created with the same name ‘XML Editor’. I don’t need this, but I can’t make it go away. I’m sure it’s something simple, I’m fairly new to plugin development.

    Here is the code that creates the menus:

    function xml_test_menu() {
    	add_menu_page(__('Playlist','menu-test'), __('XML Editor','menu-test'), 'manage_options', 'larrys_xml_editor', 'xml_edit_top_level' );
    	add_submenu_page('larrys_xml_editor', __('Add A Video','menu-test'), __('Add A Video','menu-test'), 'manage_options', "xml-add-video", "xml_add_video");
    	add_submenu_page('larrys_xml_editor', __('Delete A Video','menu-test'), __('Delete A Video','menu-test'), 'manage_options', 'xml-edit-video', 'xml_edit_video');
    }

    I only want a top-level menu called ‘XML Editor’ with no sub-menu of the same name. Gigpress and other plugins are set up like this, but looking through the code I can’t see what I’m doing wrong. Thanks

Viewing 1 replies (of 1 total)
  • I was having this issue and couldn’t find the answer anywhere. In case you haven’t found out yet, and to update everyone who may come across this post like I had.

    The default functionality is to create a submenu with the same name in order for something to be selected for the menu being displayed.

    In order to change the name of the top submenu you need to add a submenu with the same slug as the parent. I don’t know what happens if you use different menu rendering functions, but I set mine to use the same. So in your function…

    function xml_test_menu() {
    	add_menu_page(__('Playlist','menu-test'), __('XML Editor','menu-test'), 'manage_options', 'larrys_xml_editor', 'xml_edit_top_level' );
    	add_submenu_page('larrys_xml_editor', __('New Name','menu-test'), __('New Name','menu-test'), 'manage_options', 'larrys_xml_editor', 'xml_edit_top_level' );
    	add_submenu_page('larrys_xml_editor', __('Add A Video','menu-test'), __('Add A Video','menu-test'), 'manage_options', "xml-add-video", "xml_add_video");
    	add_submenu_page('larrys_xml_editor', __('Delete A Video','menu-test'), __('Delete A Video','menu-test'), 'manage_options', 'xml-edit-video', 'xml_edit_video');
    }

    Or you could modify one of your existing menus instead of creating a new menu if you only wanted the two.

Viewing 1 replies (of 1 total)
  • The topic ‘Plugin Development: New top level menu creates identical submenu. Fix?’ is closed to new replies.