The post_type_labels_{$post_type} WordPress PHP filter allows you to modify the labels of a specific post type.
Usage
add_filter('post_type_labels_post', 'customize_post_labels');
function customize_post_labels($labels) {
// Your custom code here
return $labels;
}
Parameters
- $labels (object) – An object containing labels for the post type as member variables.
More information
See WordPress Developer Resources: post_type_labels_{$post_type}
Examples
Change the Label for Posts
Change the label for WordPress posts to “Articles”:
add_filter('post_type_labels_post', 'change_post_label_to_articles');
function change_post_label_to_articles($labels) {
$labels->name = 'Articles';
return $labels;
}
Change the Label for Pages
Change the label for WordPress pages to “Static Pages”:
add_filter('post_type_labels_page', 'change_page_label_to_static_pages');
function change_page_label_to_static_pages($labels) {
$labels->name = 'Static Pages';
return $labels;
}
Customize Multiple Labels for a Custom Post Type
Customize multiple labels for a custom post type called “events”:
add_filter('post_type_labels_events', 'customize_event_labels');
function customize_event_labels($labels) {
$labels->name = 'My Events';
$labels->singular_name = 'Event';
$labels->add_new = 'Add New Event';
return $labels;
}
Change the Label for Attachments
Change the label for WordPress attachments to “Media Files”:
add_filter('post_type_labels_attachment', 'change_attachment_label_to_media_files');
function change_attachment_label_to_media_files($labels) {
$labels->name = 'Media Files';
return $labels;
}
Modify Labels for a Custom Post Type on the Fly
Modify labels for a custom post type called “products” on the fly, depending on a user’s role:
add_filter('post_type_labels_products', 'modify_product_labels_on_the_fly');
function modify_product_labels_on_the_fly($labels) {
if (current_user_can('manage_options')) {
$labels->name = 'Admin Products';
} else {
$labels->name = 'User Products';
}
return $labels;
}