Change Custom Post Type Labels

Ever need to change the labels on a custom post type created by a theme or plugin? Want to make sure you do it without modifying the files themselves? Add this code snippet to either your functions.php file or create your own plugin with it.


<?php /************************************************************** * Change Custom Post Type Labels **************************************************************/ function tft_change_custom_post_type_label() { global $wp_post_types; $v = 'testimonials'; //this is the current post type // Someone has changed this post type, always check for that! if ( empty ( $wp_post_types[$v] ) or ! is_object( $wp_post_types[$v] ) or empty ( $wp_post_types[$v]->labels )
        )
    return;

// see get_post_type_labels()
    $wp_post_types[$v]->labels->name               = 'Stories';
    $wp_post_types[$v]->labels->singular_name      = 'Story';
    $wp_post_types[$v]->labels->add_new            = 'Add story';
    $wp_post_types[$v]->labels->add_new_item       = 'Add new story';
    $wp_post_types[$v]->labels->all_items          = 'All stories';
    $wp_post_types[$v]->labels->edit_item          = 'Edit story';
    $wp_post_types[$v]->labels->name_admin_bar     = 'Story';
    $wp_post_types[$v]->labels->menu_name          = 'Story';
    $wp_post_types[$v]->labels->new_item           = 'New Story';
    $wp_post_types[$v]->labels->not_found          = 'No stories found';
    $wp_post_types[$v]->labels->not_found_in_trash = 'No stories found in trash';
    $wp_post_types[$v]->labels->search_items       = 'Search stories';
    $wp_post_types[$v]->labels->view_item          = 'View Story';
}
//Must hook into a later hook or priority than the plugin
add_action( 'wp_loaded', 'tft_change_custom_post_type_label', 20);