Change the WordPress Post Type name to Something Else

You can change the default Post type name in WordPress from Posts to something else like News using the get_post_type_object,  normal behaviour of the Posts occur just the label name in the WordPress dashboard has been changed.

wordpress-change-post-name

 

add_action( 'init', 'cp_change_post_object' );
// Change dashboard Posts to News
function cp_change_post_object() {
    $get_post_type = get_post_type_object('post');
    $labels = $get_post_type->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 News found';
        $labels->not_found_in_trash = 'No News found in Trash';
        $labels->all_items = 'All News';
        $labels->menu_name = 'News';
        $labels->name_admin_bar = 'News';
}

So the ‘post’ type is referenced as the type in get_post_type_object and a $labels variable accesses the labels property – which is then assigned the new values of ‘News’, so instead of using a new CPT you can just rename the default one if its not been used.

 

ref

2 Comments

  1. Paul Douglas on October 24, 2018 at 12:30 am

    Nice function. How then do you change the order, dashicon, and meta? Thank you!

  2. Damien Carbery on April 30, 2018 at 8:01 am

    I did something very similar for a custom post type (though the logic is the same). I used the ‘registered_post_type’ action.
    https://www.damiencarbery.com/2018/03/change-settings-of-a-cpt-custom-post-type/

Leave a Comment