Creating External Link for Admin Submenu

Have you ever wanted to add a submenu that didn’t link to a page you created? A while back, a client requested a link to a particular view and arrangement of a table in admin area of WordPress. To the best of my knowledge, there wasn’t a standard function within wordpress used to pair a submenu item, that you could customize, to a parent top level menu.

//Add a submenu under an admin menu that links to a separate page.
add_action( 'admin_menu' , 'admin_menu_new_items' );
function admin_menu_new_items() {
    global $submenu;
    $submenu['index.php'][500] = array( 'Menu item name', 'manage_options' , 'http://example.com' ); 
}

I created a the function named admin_menu_new_items. I then called the global $submenu object. The first section after list the php file you want to add that. Here’s a list of possible php files you could add.

  • index.php => Dashboard
  • edit.php => Posts
  • upload.php => Media
  • link-manager.php => Links
  • edit.php?post_type=page => Pages
  • edit-comments.php => Comments
  • themes.php => Appearance
  • plugins.php => Plugins
  • users.php => Users
  • tools.php => Tools
  • options-general.php => Settings

The last array is pretty self explanatory, the first variable contains the string to be used as the anchor and submenu. The second variable is the table used store the variable in. If your using one of the regular menu items as listed above, you’ll want to use manage_options, otherwise use whatever table your plugin or theme created for the admin menu. The last variable will be the URL for the link.

Let me know if you have a more efficient snippet or ran into a problem with my example.

Like it, Share itShare on FacebookTweet about this on TwitterShare on RedditShare on Google+Email this to someone