Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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

share|improve this question

3 Answers

up vote 2 down vote accepted

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.

share|improve this answer
Cool! could you please post the entire solution here? – Rutwick Gangurde Apr 18 '12 at 12:01
@Rutwick Gangurde - Please see edit, full solution now included. Be warned that this an English only solution. To allow multi-language you would have to alter the code to use __() calls – Brady Apr 18 '12 at 12:05
Yep... Thanks a lot! – Rutwick Gangurde Apr 18 '12 at 12:27

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' );
share|improve this answer

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.

share|improve this answer
Can be done. Please see my answer. However placing in a different order cannot be done from what I can tell. Even by removing and re-adding would always place the new item at the bottom. – Brady Apr 18 '12 at 12:02
Nice! Btw, changing the priority of the action allows you to decide the position of the new item! Check my post, I've explained it! – Rutwick Gangurde Apr 18 '12 at 12:04
Changing priority wouldn't work in the drop down as that drop down is run at 70 and the items inside are all done in one go. – Brady Apr 18 '12 at 12:07
Ohh... I guess I'll try it again and then comment! ;) – Rutwick Gangurde Apr 18 '12 at 12:26
A priority '10' for the action adds my item at the top, above 'Post'... – Rutwick Gangurde Apr 18 '12 at 12:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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