13

Thanks for your time.

I want to have the WordPress dashboard treat Posts (vanilla, not custom post types or anything) exactly as normal, but to replace the word with something else. I've tried plugins that claim to do this and they replace it in some locations but not others.

The hardest location to change has been at "view all posts" where the word stubbornly refuses to change from "Posts" at the title even with site-wide text replacement via plugin.

What is the correct way to inform WordPress that I want to call Posts by a different name?

Puck
  • 217
  • 1
  • 3
  • 11
  • We occasionally provide the French admin screen for our clients, which changes "Post" to "Article". Would creating a custom "translation", just changing "post" be an acceptable approach for you? – Hobo Oct 01 '14 at 16:26
  • Interesting. Two questions: 1. Does that replace all instances sitewide on the dashboard? And 2. Does that replace user content in "title" and "description" fields? We can't have user content modified by this of course, it would need to only be in the admin panel. ---- Thought of one other potential concern, if it effects text entered by administrators and they view the page they wrote and then re-save it, will it change the text there as well corrupting the Publish data? – Puck Oct 01 '14 at 16:34
  • It'd only change the labels, not the content (WordPress doesn't save anything differently just because the admin is in French, for example). For example, a translation would replace `__('Posts')` [here](https://core.trac.wordpress.org/browser/tags/4.0/src/wp-admin/menu.php#L49) with your text. But it looks like Daniel Cooley's answer will do what you need, so adding a translation might be overkill – Hobo Oct 02 '14 at 07:12
  • Appreciate the input tho. – Puck Oct 02 '14 at 23:08

1 Answers1

20

Put this in your functions.php file (obviously change "News Articles" to whatever you want the post name to be):

// Function to change "posts" to "news" in the admin side menu
function change_post_menu_label() {
    global $menu;
    global $submenu;
    $menu[5][0] = 'News Articles';
    $submenu['edit.php'][5][0] = 'News Articles';
    $submenu['edit.php'][10][0] = 'Add News Article';
    $submenu['edit.php'][16][0] = 'Tags';
    echo '';
}
add_action( 'admin_menu', 'change_post_menu_label' );
// Function to change post object labels to "news"
function change_post_object_label() {
    global $wp_post_types;
    $labels = &$wp_post_types['post']->labels;
    $labels->name = 'News Articles';
    $labels->singular_name = 'News Article';
    $labels->add_new = 'Add News Article';
    $labels->add_new_item = 'Add News Article';
    $labels->edit_item = 'Edit News Article';
    $labels->new_item = 'News Article';
    $labels->view_item = 'View News Article';
    $labels->search_items = 'Search News Articles';
    $labels->not_found = 'No News Articles found';
    $labels->not_found_in_trash = 'No News Articles found in Trash';
}
add_action( 'init', 'change_post_object_label' );

And if you are worried about translation (based on the comments to your question), just add the appropriate __( 'News Articles', 'my-text-domain' ); function for each item...

Daniel C
  • 2,105
  • 12
  • 18
  • Does ` $menu[5][0] = 'News Articles';` assume that Posts is in the default position of 5? What if you have changed the position? – gillespieza Sep 06 '16 at 15:30
  • Yes... that is the assumption. If you have changed the menu position, change the [5] accordingly. If you don't know where you put it, you can do an `echo '
    '; var_dump( $menu ); echo '
    ';` to see which position it's in! Do the same for `$submenu`. Hope this helps.
    – Daniel C Sep 06 '16 at 16:24