3

Is it possible to create a new set of categories right after the default set of categories?

For example, in the WP admin area, this is what we see and get by default:

Pages
- All Pages
- Add New
- Categories
- Tags

I would like to create another set for categories, so:

Pages
- All Pages
- Add New
- Categories
- My New Categories
- Tags

Is this possible?

  • 1
    Yes. You can create a Custom Taxonomy that is linked to a particular post type - whether Page, Post, or CPT - and it will appear in the wp-admin menu under whichever post type(s) it is assigned to. – WebElaine Aug 20 '18 at 17:52
2

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
        )
)
  • but it seems that it is adding a new set of tags, not categories. – laukok Aug 20 '18 at 18:28
  • @laukok It moves "tags" to the end of array – nmr Aug 20 '18 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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