Add menu and submenu in admin with a URL instead of slug?

I use this function and hook:

function mysite_admin_menu() 
{
  add_menu_page( 'Categories', 'Catégories', 'administrator', 'categories', 'a_function' );
  add_submenu_page( 'categories', 'Manage', 'Manage', 'administrator', 'xxx', 'a_function' );
  remove_submenu_page('categories','categories');
}
add_action( 'admin_menu', 'mysite_admin_menu' );

It displays what I need: a menu with a submenu on the left admin menu bar.

The thing is, the submenu leads to this page: admin.php?page=xxx.

How can I do to link to a URL like edit-tags.php?taxonomy=category?

If I swap the slug in the add_submenu_page with a relative URL, the link will lead to
admin.php?page=edit-tags.php?taxonomy=category.

Whatever I do, I always get admin.php?page=... which is not what I want.

5 s
5

This is an old post but can’t you just use wordpress $menu and/or $submenu globals like Oleg suggested in number 2.

When in doubt copy WordPress:

wordpress/wp-admin/menu.php

For example to add link this seems like it would work:

function add_external_link_admin_submenu() {
    global $submenu;
    $permalink = admin_url( 'edit-tags.php' ).'?taxonomy=category';
    $submenu['options-general.php'][] = array( 'Manage', 'manage_options', $permalink );
}
add_action('admin_menu', 'add_external_link_admin_submenu');

You can replace the $permalink = ... with anything

So this should also work :

$permalink = 'http://www.example.com';

Also, it’s suggested not to use ‘administrator’ (even though I use it as well. Anyway, read this ticket for alternative solutions.

Leave a Comment