Custom taxonomy admin page

If you want a custom admin page for a taxonomy, you can set 'show_ui' => false when you register it to suppress the default admin page and then create a new admin page to replace it.

However edit-tags.php?taxonomy=taxonomy-slug still takes you to the ‘hidden’ default admin page. Is there way of directing it instead to the custom admin page. Or otherwise is there another method than circumvents this issue?

Related posts

Leave a Reply

2 comments

  1. Not sure why I didn’t think of this earlier. I suppose I was hoping for a way to ‘hijack’ the default page to display something else… Anyway following my original method:

    If you want a custom admin page for a taxonomy, you can set ‘show_ui’ => false when you register it to suppress the default admin page and then create a new admin page to replace it.

    You can get round the issue of edit-tags.php?taxonomy=taxonomy-slug taking you to the hidden taxonomy page, by simply redirecting the user to your page, using wp_redirect:

    add_action('load-edit-tags.php','myprefix_redirect_to_custompage');
    function myprefix_redirect_to_custompage(){
        $screen = get_current_screen(); 
        if($screen->id == 'edit-mytax'){
            $url = admin_url('edit.php?page=mypage');
            wp_redirect($url); 
            exit;
        }
    }
    

    Assuming mytax is the taxonomy name. $url should be the url of the custom page replacing the default taxonomy page.

  2. Do a simple redirect:

    if ( CONDITION_SEE_BELOW )
    {
        wp_redirect( admin_url( 'edit.php?post_type=YOUR_CPT', is_ssl() ? 'https' : 'http' ); );
        // faster then die();
        exit;
    }
    

    I tried to take the whole pages thing apart and wrote a table to sum them up and get definitive hints about where you currently are in this paste.

    To list them here:

    1. global $menunot possible
    2. global $submenuslug edit-tags.php?taxonomy=YOUR_TAX
    3. global $current_screenid edit-YOUR_TAX 1)
    4. global $selfedit-tags.php 1) 2)
    5. $GLOBALS['$_SERVER']['REQUEST_URI']edit-tags.php?taxonomy=YOUR_TAX 1)

    1) Be sure to also check…

    if ( edit.php?post_type=YOUR_CPT === $GLOBALS['current_screen']['parent_file'] )

    …in case your tax is registered elsewhere too.

    2) This will only help if a) you’re that you ain’t got another tax registered or b) if you want to redirect them all.