Support » Fixing WordPress » Creating Admin Menus/Screens

  • Resolved ooeygui


    Ok, I’ve been toiling over this one for quite a while.

    When using the add_menu_page() and add_submenu_page() functions WordPress automatically assumes that you’re wanting to put it into the sidebar of the admin screens.

    Is there a way to create a page within the admin section that won’t go into the sidebar and wont show the “You don’t have permission to access this page” error?

    In the past I’ve had to modify a sidebar page to do something like this;

    switch ($_REQUEST["var"]){
        case "page1" :
            // Output this
        default :
            // Output the default admin page
Viewing 6 replies - 1 through 6 (of 6 total)
  • Just do what you usually do but unset the menu item after you register the menu page..

    add_action( 'admin_menu' , 'my_pages_etc' );
    function my_pages_etc() {
    	global $menu, $submenu;
    	// Empty values as this is for illustration only
    	add_menu_page( '', '', '', '', '', '', '100' ); // 7th parameter is position in menu array
    	add_submenu_page( ... ); // For illustration only
    	unset( $menu[100] ); // Unset the menu item registered above

    The page will still function, they’ll just not be a link to it in the menu… 🙂

    Nice, I’ll have to give that a try. Thanks.

    Be sure to global the necessary vars inside your function first, per the example above.

    I actually do alot of menu tweaking for my local installs so this is quite simple stuff for me, if you have any questions, shoot…

    Happy to help in any case.. 😉

    Hmm, this only works on top level admin menus which is ok, but apparently I can only add one top level menu per plugin. I didn’t realize this. For some reason when I try to add more than one it forces the link on the menu over to an actual page. For example, “” rather than “” and this gives me a 404 error.

    I only need to hide certain items so I need to be able to create more top level menus or be able to hide the sub menus.

    Ok nevermind, I got it.

    When I only define a top level it puts that weird URL in there so I needed to define a submenu underneath it with the same slug.

    Small tip, you can create more specific menus by adding thme into the menu array manually..

    Take a look at how menu.php adds the various menu items, you can do the same if you register them inside the action for admin_menu.

    The advantage of adding items manually is that you can have the menu items link offsite, where as the functions for adding items force a URL relative to the current site.

    I’ve actually added a couple myself.

    Options – links to options.php for the current site (there’s no link to it otherwise)
    WordPress 2.9 – links to the 2.9 admin (screenshot is trunk install)
    bbPress – links to installation of bbPress trunk

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Creating Admin Menus/Screens’ is closed to new replies.