Categories – create a new separate set right after the default?

When you create custom taxonomy use post as object type for the taxonomy:

register_taxonomy('your_custom_taxonomy', 'post', $args);

New custom taxonomy will appear at the end of “Posts” submenu, below “Tags”. To change this order add this code (to functions.php or plugin file):

add_filter('menu_order', 'reorder_post_submenu', 15);
function reorder_post_submenu($menu_order) {    
    global $submenu;

    if (isset($submenu, $submenu['edit.php'])) {
        $i_offset = strlen('taxonomy=');
        $tmp_order = false;
        foreach ($submenu['edit.php'] as $key => &$value) {
            $i_txm = strpos($value[2], 'taxonomy=');
            if ($i_txm === false)
                continue;
            $name = substr($value[2], $i_txm + $i_offset);
            if ($name == 'post_tag' ) {
                // get last item key
                $last = array_pop( array_keys($submenu['edit.php']) );
                // move "tag" menu item to the end
                $submenu['edit.php'][$last + 5] = $value;
                unset($submenu['edit.php'][$key]);
                break;
            }
        }
    }
    return $menu_order;
}

Default posts submenu looks like this:

[edit.php] => Array (
    // ["label", "capability", "page"] 
    [5] => Array (
            [0] => All Posts
            [1] => edit_posts
            [2] => edit.php
        )
    [10] => Array (
            [0] => Add New
            [1] => edit_posts
            [2] => post-new.php
        )
    [15] => Array (
            [0] => Categories
            [1] => manage_categories
            [2] => edit-tags.php?taxonomy=category
        )
    [16] => Array (
            [0] => Tags
            [1] => manage_post_tags
            [2] => edit-tags.php?taxonomy=post_tag
        )
)

Leave a Comment