Post Pic

How to change the “posts” label to “articles”

Are you working for clients which aren’t very good with technology? If yes, most of them might find the term “post” a bit confusing, while “article” can be seen as much self-explanatory. Today, I’m going to show you how you can easily change the “post” label to “articles”.

Nothing complicated: Open your functions.php file, paste the code below in it. Save the file, and you're done!

add_filter('gettext',  'change_post_to_article');
add_filter('ngettext',  'change_post_to_article');

function change_post_to_article($translated) {
     $translated = str_ireplace('Post',  'Article',  $translated);  
     return $translated;
}

Thanks to Smashing Magazine for the cool tip!

10 Responses

Apr 16 2012 17:31

Wrote this on Smashing, will repeat here: Why would you run a replace function on each an every call to gettext and ngettext? Not only is that inefficient, but it will also break when you want to change your posts to “news” and you’ll end up with labels like “Delete Newss”. Also, it might (and probably will) break some other non-related translations, like “post by e-mail” will become “article by e-mail”, and “post a comment” will become “article a comment” — wtf?

The correct solution probably lies somewhere around the $wp_post_types globals, register_post_type and get_post_type_labels.

Apr 16 2012 18:42

I always use this code example to accomplish it. Little bit because of the reasons Konstantin gave. It’s better to have full control over what you do then hoping it will work because of luck.

Apr 16 2012 18:42

My bad. Here is the link: https://gist.github.com/2399864

Apr 16 2012 18:49

The way I would do it:

function change_post_menu_label() {
global $menu;
global $submenu;
$menu[5][0] = ‘Article’;
$submenu['edit.php'][5][0] = ‘Article’;
$submenu['edit.php'][10][0] = ‘New Article’;
$submenu['edit.php'][16][0] = ‘Tags’;
echo ”;
}
function change_post_object_label() {
global $wp_post_types;
$labels = &$wp_post_types['post']->labels;
$labels->name = ‘Article’;
$labels->singular_name = ‘Article’;
$labels->add_new = _x(‘Create’, ‘Article’);
$labels->add_new_item = ‘Create new article’;
$labels->edit_item = ‘Edit article’;
$labels->new_item = ‘New article’;
$labels->view_item = ‘View article’;
$labels->search_items = ‘Search articles’;
$labels->not_found = ‘No articles found’;
$labels->not_found_in_trash = ‘No articles found in trash.’;
}
add_action( ‘init’, ‘change_post_object_label’ );
add_action( ‘admin_menu’, ‘change_post_menu_label’ );

Apr 17 2012 02:24

This is so broken. Post means an institution in German, and Article is not even a word. This code will change ‘Postangestellte’ to ‘Articleangestellte’.

Apr 17 2012 09:20

is that enough? what about plurals?

Apr 25 2012 10:18

I agree with Kovshenin that its inefficient and that custom post types are better for this purpose.

Jorin’s solution seems interesting however he is referencing a hard-coded array index and changing that name, what if WordPress add another option near the top (or another plugin does), you would then be changing the incorrect menu item.

Apr 26 2012 04:16

Completely agree with Konstantin, this needs to be taken down. Just spotted an “Article a comment” button on a website and had a giggle.

Aug 26 2012 20:26

Oh dear, I used this, but I then wanted to create a form with ‘Post Code’ in it, and have ended up with ‘Articleal Code’. Removing the code from the functions file doesn’t change things back though, and swapping the two words around doesn’t seem to do it either.

I’m at the point where I may just have to start over with the site :0(

Aug 28 2012 12:28

Totally agree with others here, this really needs to be taken down or ammended as I nearly used the code myself before checking out the comments.

This is a really bad example.

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox