• Pete

    (@perthmetro)


    I have a custom post type called Suburbs. It appears in the admin menu. like a normal post there are 4 sub menus…
    1. Suburbs
    2. Add new
    3. Categories
    4. Tags

    I want to rename the ‘Categories’ and/or the ‘Tags’ sub menu. I have this code but I can’t figure out how to adapt it to a CT or the Category/Tag sub menus?

    function wptutsplus_change_post_menu_label() {
        global $menu;
        global $submenu;
        $menu[5][0] = 'News';
        $submenu['edit.php'][5][0] = 'News Items';
        $submenu['edit.php'][10][0] = 'Add News Item';
    }
    add_action( 'admin_menu', 'wptutsplus_change_post_menu_label' );

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi,
    You need to figure out the index for Suburbs:

    function change_post_menu_label() {
        global $menu;
        global $submenu;
        echo "<pre>";
        print_r($menu);
        print_r($submenu);
        echo "</pre>";
        $submenu['edit.php'][15][0] = 'Status'; // Change name for categories
        $submenu['edit.php'][16][0] = 'Labels'; // Change name for tags
    }

    For that you need to print the $menu array and $submenu. after you get the index, replace the index 15 and 16 in above code to rename the category and label.

    Thread Starter Pete

    (@perthmetro)

    Sorry it didn’t work…

    function change_post_menu_label() {
        global $menu;
        global $submenu;
        echo "<pre>";
        print_r($menu);
        print_r($submenu);
        echo "</pre>";
        $submenu['edit-tags.php?taxonomy=category&post_type=property-for-sale'][15][0] = 'Property Type'; // Change name for categories
        $submenu['edit-tags.php?taxonomy=post_tag&post_type=property-for-sale'][16][0] = 'Labels'; // Change name for tags
    }

    You have specified a wrong index, it is supposed to be like below code:

    [5] => Array
            (
                [0] => Posts
                [1] => edit_posts
                [2] => edit.php
                [3] =>
                [4] => open-if-no-js menu-top menu-icon-post
                [5] => menu-posts
                [6] => dashicons-admin-post
            )

    This is part of $menu array, it is for Posts menu, similarily for custom posts, you’ll get an array in $menu.
    The index $menu[5][2], specifies the index for submenu i.e. edit.php in case of posts, for CPT it might be something else you need ot check that in array.
    Now lookup in $submneu for above edit.php

    [edit.php] => Array
            (
                [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_categories
                        [2] => edit-tags.php?taxonomy=post_tag
                    )
    
            )

    The above array is for submenu of post, for renaming the Category, you need to do
    $submenu['edit.php'][15][0] = 'Status';

    which renames category to Status.

    Thread Starter Pete

    (@perthmetro)

    How do I find the numerical indexes for the menu items of my CPT?

    Maybe you could directly use a plugin, https://wordpress.org/plugins/admin-menu-editor/

    If you don’t want to use a plugin, when you print the $menu and $submenu array, what do you get on screen?

    Can you post those arrays here?

    Thread Starter Pete

    (@perthmetro)

    How do i print the $menu and $submenu array?

    function wptutsplus_change_post_menu_label() {
        global $menu;
        global $submenu;
        echo "<pre>";
        print_r($menu);
        print_r($submenu);
        echo "</pre>";
    }
    add_action( 'admin_menu', 'wptutsplus_change_post_menu_label' );

    Ad this code and paste the arrays here

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to rename the admin sub menu name of a custom post 'category' or 'tag'’ is closed to new replies.