9

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?

4

1 回答 1

15

将其放入您的 functions.php 文件中(显然将“新闻文章”更改为您想要的帖子名称):

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

如果您担心翻译(基于对您问题的评论),只需__( 'News Articles', 'my-text-domain' );为每个项目添加适当的功能......

于 2014-10-01T17:13:17.490 回答