将标签帖子更改为Wordpress中的文章

时间:2012-10-18 07:54:35

标签: wordpress wordpress-plugin wordpress-theming

我正在研究wordpress。任何人都可以帮助我如何在wordpress中更改管理面板菜单标签。

具体来说,我想将帖子的标签更改为文章。以及Posts to Article的管理面板中的所有实例。

请告知。

3 个答案:

答案 0 :(得分:11)

以下是您需要添加到主题函数文件中的代码。

// Replace Posts label as Articles in Admin Panel 

function change_post_menu_label() {
    global $menu;
    global $submenu;
    $menu[5][0] = 'Articles';
    $submenu['edit.php'][5][0] = 'Articles';
    $submenu['edit.php'][10][0] = 'Add Articles';
    echo '';
}
function change_post_object_label() {
        global $wp_post_types;
        $labels = &$wp_post_types['post']->labels;
        $labels->name = 'Articles';
        $labels->singular_name = 'Article';
        $labels->add_new = 'Add Article';
        $labels->add_new_item = 'Add Article';
        $labels->edit_item = 'Edit Article';
        $labels->new_item = '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' );

改编自:https://wordpress.stackexchange.com/questions/9211/changing-admin-menu-labels

答案 1 :(得分:1)

在您的主题函数文件中包含以下行:

//Change Posts labels in sidebar admin menu
  function custom_post_menu_label() {
     global $menu;
     global $submenu;
     $menu[5][0] = 'News';
     $submenu['edit.php'][5][0] = 'News';
     $submenu['edit.php'][10][0] = 'Add News';         
  }

 //Change Posts labels in other admin area
  function custom_post_object_label() {
    global $wp_post_types;
    $labels = &$wp_post_types['post']->labels;
    $labels->name = 'News';
    $labels->singular_name = 'News';
    $labels->add_new = 'Add News';
    $labels->add_new_item = 'Add News';
    $labels->edit_item = 'Edit News';
    $labels->new_item = 'News';
    $labels->view_item = 'View News';
    $labels->search_items = 'Search News';
    $labels->not_found = 'No results on News';
    $labels->not_found_in_trash = 'No News in Trash';
    $labels->name_admin_bar = 'Add News';       

   }

 add_action( 'init', 'custom_post_object_label' );
 add_action( 'admin_menu', 'custom_post_menu_label' );

之前回答的作者忘记包含' $ labels-> name_admin_bar ='添加新闻';'字符串。

答案 2 :(得分:1)

我能够使用像这样的post_type_labels_{$post_type}过滤器来解决这个问题

add_filter( 'post_type_labels_post', 'change_post_labels' );

function change_post_labels( $args ) {
        foreach( $args as $key => $label ){
            $args->{$key} = str_replace( [ __( 'Posts' ), __( 'Post' ) ], __( 'News' ), $label );
        }

        return $args;
}

这个答案也保留了翻译支持。唯一需要注意的是,您可能需要从插件中运行它,因为主题加载太晚了。