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

Kru*_*nal 6 wordpress wordpress-theming wordpress-plugin

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

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

好心提醒.

Kru*_*nal 12

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

// 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' );
Run Code Online (Sandbox Code Playgroud)

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


Mat*_*ipe 11

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

add_filter( 'post_type_labels_post', 'change_post_labels' );

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

        return $args;
}
Run Code Online (Sandbox Code Playgroud)

这个答案也使翻译支持完好无损。

唯一需要注意的是,您必须在init操作触发之前添加过滤器。