Change existing label in the admin bar with something else

In the admin bar an admin can create a new post by using the add new drop down. In there I want to change the label Post to something else.

How can I do this? I just need the code to make the change in the admin bar as I have the code already to change the Post label everywhere else in the admin section.

Read More

Bonus points if you can tell me how to change the order of the labels in the drop down too.

Related posts

Leave a Reply

4 comments

  1. Found my answer including my full solution:

    <?php
    /*
    Plugin Name: Rename Posts to News
    Description: Rename built in posts to be called News
    Version: 1.0
    Author: Scott Cariss @ Philosophy Design
    Author URI: http://www.philosophydesign.com
    */
    
    // Not a WordPress context? Stop.
    ! defined( 'ABSPATH' ) and exit;
    
    
    add_action( 'init', array ( 'chg_Posts_to_News', 'init' ) );
    add_action( 'admin_menu', array ( 'chg_Posts_to_News', 'admin_menu' ) );
    
    class chg_Posts_to_News
    {
        public static function init()
        {
            global $wp_post_types;
            $labels = &$wp_post_types['post']->labels;
            $labels->name = 'Corporate News';
            $labels->singular_name = 'Corporate News';
            $labels->add_new = 'Add Corporate News';
            $labels->add_new_item = 'Add Corporate News';
            $labels->edit_item = 'Edit Corporate News';
            $labels->new_item = 'Corporate News';
            $labels->view_item = 'View Corporate News';
            $labels->search_items = 'Search Corporate News';
            $labels->not_found = 'No corporate news found';
            $labels->not_found_in_trash = 'No corporate news found in trash';
            $labels->name_admin_bar = 'Corporate News';
        }
    
        public static function admin_menu()
        {
            global $menu;
            global $submenu;
            $menu[5][0] = 'Corporate News';
            $submenu['edit.php'][5][0] = 'Corporate News';
            $submenu['edit.php'][10][0] = 'Add Corporate News';
        }
    }
    ?>
    

    Just needed change the label $labels->name_admin_bar = 'Corporate News';

    Looking through the function wp_admin_bar_new_content_menu( $wp_admin_bar ) that deals with placing these drop down menu items there are no filters or hooks there that will allow me to change the order so I can only presume its not doable without some JS hacks.

  2. UPDATE: If you find this answer, please don’t do this. Use $wp_post_types['post']->labels->name_admin_bar instead, as shown above.


    Sloppy and hackish, I know, but here’s how I changed “Post” under the “New” dropdown in the admin bar to read “Project”:

    function change_post_admin_bar_label() {
        ?>
        <script type="text/javascript">
            jQuery(document).ready(function($) {
                $('#wp-admin-bar-new-post > a').text('Project');
            });
        </script>
        <?php
    }
    add_action( 'wp_after_admin_bar_render', 'change_post_admin_bar_label' );
    
  3. As far as I know, you can’t, cause there is no filter applied to that label. (Check wp-includes/admin-bar.php, line 364).

    But you can remove the current one, and add your own link to do the same function, i. e. add new post. Check this to know the method.