add_submenu_page not working
-
I have followed the examples on this codex page as well as this one, but I just can’t get custom submenus to work properly.
I hook into the ‘admin_menu’ action:
add_action('admin_menu', array(&$this, 'add_menu'));
Then I have the following function which handles the action and adds the menus:
public function add_menu() { add_menu_page('Page title', 'Top-level menu title', 'manage_options', 'my-top-level-handle', array(&$this, 'main_menu_page')); // first submenu is a duplicate of the toplevel menu as per the second codex link above add_submenu_page('my-top-level-handle', 'Page Title', 'Top-level menu title', 'manage-options', 'my-top-level-handle', array(&$this, 'main_menu_page')); add_submenu_page('my-top-level-handle', 'Page Title', 'Sub-menu title', 'manage-options', 'my-submenu-handle', array(&$this, 'main_menu_page')); add_submenu_page('my-top-level-handle', 'Page Title', 'Sub-menu title 2', 'manage-options', 'my-submenu-handle2', array(&$this, 'main_menu_page')); }
I also have this function to print contents:
public function main_menu_page() { echo "Hello menu!"; }
However much I try, none of the submenus are visible, and if I click the top-level menu I get the “You do not have sufficient permissions to access this page.” message.
If I remove the first add_submenu_page line (the “duplicate”), then I no longer get the “sufficient permissions” message, and “Hello menu!” is displyed, but still no sub menus are visible.What am I doing wrong?
- The topic ‘add_submenu_page not working’ is closed to new replies.