2

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.

4 Answers 4

4

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
  • Cool! could you please post the entire solution here? Apr 18, 2012 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
    – Scott
    Apr 18, 2012 at 12:05
1

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' );
0

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.

5
  • 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.
    – Scott
    Apr 18, 2012 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! Apr 18, 2012 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.
    – Scott
    Apr 18, 2012 at 12:07
  • Ohh... I guess I'll try it again and then comment! ;) Apr 18, 2012 at 12:26
  • A priority '10' for the action adds my item at the top, above 'Post'... Apr 18, 2012 at 12:39
-1

Here is a quite well written tut about it and even more.. http://wp.tutsplus.com/tutorials/creative-coding/customizing-your-wordpress-admin/

5
  • 1
    Not to discourage you - the tutorial you linked to might be of quality and useful - nonetheless, answers should not consist of a link only. What if the resource becomes unavailable? The answer will inevitably be useless. Aug 8, 2013 at 20:35
  • Johannes thanks for the minus :)) However I did not think that tutplus.com may just gone(unavailable) in near future.. But I do agree I might be more detailed.. just didn't want to create additional noise in here..
    – Alex Reds
    Aug 8, 2013 at 20:39
  • Though comment and vote are not inherently related, the latter is indeed mine. Whether the answer deserves a downvote might be debatable. But: 1. Votes are not necessarily permanent. Improve the answer with code and explanations here and the vote is not only revocable, it would even be reversible. 2. Reputation cannot decrease below 1. Had you had a little more rep already, I might have chosen not to lower it. In this case though, it didn't matter, @Alex. Aug 8, 2013 at 22:17
  • Johannes, I am not quite hungry for those votes to be honest.. as they say couldn't care less :) I came here to help and share what I know.. I noticed that the TS had the same question I had recently.. And I thought why not share some good resource and piese of mind, perhaps TS will find that useful.. We all in here constantly searching something.. and thanks for the invention of sharing.. we all now can benefit from that.. So I shared resource.. To put it up more detailed might be no point.. as no point to rewrite and dublicate it.. TS w
    – Alex Reds
    Aug 9, 2013 at 1:01
  • TS would better benefit from reading the actual source rather than duplication. He seems not a copy&paste guy.. Bottom line.. if sharing of links in such way is against the local rulers.. That's ok.. Next time I will know.. Otherwise I believe I added value to the topic.. therefor your downvote indeed debatable :)) But as I said I am not worrying much about it.. I don't need those gamification or other artificial triggers to share my experience..
    – Alex Reds
    Aug 9, 2013 at 1:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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