Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change label Posts to Articles in Wordpress

I'm working on wordpress. Can anybody help me how can I change admin panel menu label in wordpress.

Specifically, I want to change the label for Posts to Articles. And all of the instances in admin panel of Posts to Article.

Kindly advise.

like image 423
Krunal Avatar asked Oct 18 '12 07:10

Krunal


People also ask

How do I change the label on a Wordpress post?

In your theme functions file include these lines: //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.

How do I change the default post name in Wordpress?

You can, of course, change “Posts” to anything you want…just replace every instance of “News” in the code below with your desired label. All you need to do is paste this into your theme's functions. php file. add_action( 'admin_menu' , 'revcon_change_post_label' );


2 Answers

Here is the code you need to add into your theme functions file.

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

Adapted from: https://wordpress.stackexchange.com/questions/9211/changing-admin-menu-labels

like image 120
Krunal Avatar answered Sep 28 '22 17:09

Krunal


I was able to solve this using the post_type_labels_{$post_type} filter like so

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;
}

This answer also leaves translation support intact. The only note is you will probably have to run it from a plugin because the theme loads too late.

like image 26
Mat Lipe Avatar answered Sep 28 '22 19:09

Mat Lipe