Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
see updated example =) –  Oleg Butuzov Jan 31 '13 at 6:02

3 Answers 3

Firstly, not recoment you do that.

Secondly

lets assume your prefix for admin.php is '_trigger_me_'

  1. Submenu

    <?php
    
    function _clean_url_to_repalce_admin_menu($url, $original_url, $_context){
        if ($url == 'admin.php?page=_trigger_me_'){
            remove_filter('clean_url', '_clean_url_to_repalce_admin_menu', 10);
            //return admin_url('someotherpage.php);
            return 'http://google.com/';
        }
    }
    if (is_admin())
    add_filter('clean_url', '_clean_url_to_repalce_admin_menu', 10, 3);
    
  2. Main Menu

    <?php
    function custom_admin_menu_action_hook(){
        global $menu;
        foreach($menu as $k=>$item){
            if ($item[2] == '_trigger_me_'){
                    $menu[$k][2] = 'http://google.com';
            }
        }
    }
    add_action('admin_menu', 'custom_admin_menu_action_hook', 100);
    

I call both examples as "hacks". Thay posible to do, but better to not do that.

update.

if case if satisfied with redirection =)

<?php
$hook = add_submenu_page($parent, $title, $menu_title, 'manage_option', 'callback');
add_action("load-{$hook}", create_function('','
    header("Location:", admin_url("someurl.php?blahblahblah"));
    exit;
'));

in case if you want to substitute this by taxonomy page (edit-tags.php)

<?php
add_action('admin_menu', 'admin_menu_edit_tags_page');
function admin_menu_edit_tags_page(){
    // please set $YOURPARENTSLUG as parent slug of your menu item (parent of your menu)
    // manage_tags to manage_terms of your taxonomy capability (its visible whan you var_dump($wp_taxonomies[$taxonomyyouwant]));
    add_submenu_page($YOURPARENTSLUG, 'menu', 'title', 'manage_tags',  'edit-tags.php?taxonomy=taxonomy');
}
share|improve this answer

Thank you Oleg, your script works but breaks the admin interface (background colors and images all dissappear for any reason).

But if I have to take this road, I can do this instead:

function changeUrl()
{
    $pageURL = 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

    if ($pageURL == 'http://www.mysite.com/wp-admin/admin.php?page=xxxx')
    {
        header ('location:http://www.mysite.com/wp-admin/edit-tags.php?taxonomy=category');
    }
}
add_action( 'admin_menu', 'changeUrl' );

It's seems curious to me that there is no simple way to link a submenu to any url. This kind of redirection is messy...but it works.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.