Rename a Plugin's Post Type
Changes the name a theme or plugin gave its post type everywhere in the admin, for example "Projects" to "Case Studies", without touching URLs or content.
Opens WPIDE on
Code
// Post type and its new names.
$wpide_relabel = array(
'post_type' => 'portfolio',
'singular' => 'Case Study',
'plural' => 'Case Studies',
);
add_filter( 'register_post_type_args', function ( $args, $post_type ) use ( $wpide_relabel ) {
if ( $wpide_relabel['post_type'] !== $post_type ) {
return $args;
}
$s = $wpide_relabel['singular'];
$p = $wpide_relabel['plural'];
$args['label'] = $p;
$args['labels'] = array_merge( (array) ( $args['labels'] ?? array() ), array(
'name' => $p,
'singular_name' => $s,
'menu_name' => $p,
'all_items' => "All $p",
'add_new_item' => "Add New $s",
'edit_item' => "Edit $s",
'new_item' => "New $s",
'view_item' => "View $s",
'view_items' => "View $p",
'search_items' => "Search $p",
'archives' => "$s Archives",
) );
return $args;
}, 10, 2 );
Notes
Only the labels change; use the slug snippet to change URLs as well.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.