Builds an object with all post type labels out of a post type object.
Description
Accepted keys of the label array in the post type object: <ul> <li>name - General name for the post type, usually plural. The same and overridden by $post_type_object->label. Default is 'Posts' / 'Pages'.</li> <li>singular_name - Name for one object of this post type. Default is 'Post' / 'Page'.</li> <li>add_new - Label for adding a new item. Default is 'Add Post' / 'Add Page'.</li> <li>add_new_item - Label for adding a new singular item. Default is 'Add Post' / 'Add Page'.</li> <li>edit_item - Label for editing a singular item. Default is 'Edit Post' / 'Edit Page'.</li> <li>new_item - Label for the new item page title. Default is 'New Post' / 'New Page'.</li> <li>view_item - Label for viewing a singular item. Default is 'View Post' / 'View Page'.</li> <li>view_items - Label for viewing post type archives. Default is 'View Posts' / 'View Pages'.</li> <li>search_items - Label for searching plural items. Default is 'Search Posts' / 'Search Pages'.</li> <li>not_found - Label used when no items are found. Default is 'No posts found' / 'No pages found'.</li> <li>not_found_in_trash - Label used when no items are in the Trash. Default is 'No posts found in Trash' / 'No pages found in Trash'.</li> <li>parent_item_colon - Label used to prefix parents of hierarchical items. Not used on non-hierarchical post types. Default is 'Parent Page:'.</li> <li>all_items - Label to signify all items in a submenu link. Default is 'All Posts' / 'All Pages'.</li> <li>archives - Label for archives in nav menus. Default is 'Post Archives' / 'Page Archives'.</li> <li>attributes - Label for the attributes meta box. Default is 'Post Attributes' / 'Page Attributes'.</li> <li>insert_into_item - Label for the media frame button. Default is 'Insert into post' / 'Insert into page'.</li> <li>uploaded_to_this_item - Label for the media frame filter. Default is 'Uploaded to this post' / 'Uploaded to this page'.</li> <li>featured_image - Label for the featured image meta box title. Default is 'Featured image'.</li> <li>set_featured_image - Label for setting the featured image. Default is 'Set featured image'.</li> <li>remove_featured_image - Label for removing the featured image. Default is 'Remove featured image'.</li> <li>use_featured_image - Label in the media frame for using a featured image. Default is 'Use as featured image'.</li> <li>menu_name - Label for the menu name. Default is the same as name.</li> <li>filter_items_list - Label for the table views hidden heading. Default is 'Filter posts list' / 'Filter pages list'.</li> <li>filter_by_date - Label for the date filter in list tables. Default is 'Filter by date'.</li> <li>items_list_navigation - Label for the table pagination hidden heading. Default is 'Posts list navigation' / 'Pages list navigation'.</li> <li>items_list - Label for the table hidden heading. Default is 'Posts list' / 'Pages list'.</li> <li>item_published - Label used when an item is published. Default is 'Post published.' / 'Page published.'</li> <li>item_published_privately - Label used when an item is published with private visibility.Default is 'Post published privately.' / 'Page published privately.'</li> <li>item_reverted_to_draft - Label used when an item is switched to a draft.Default is 'Post reverted to draft.' / 'Page reverted to draft.'</li> <li>item_trashed - Label used when an item is moved to Trash. Default is 'Post trashed.' / 'Page trashed.'</li> <li>item_scheduled - Label used when an item is scheduled for publishing. Default is 'Post scheduled.' / 'Page scheduled.'</li> <li>item_updated - Label used when an item is updated. Default is 'Post updated.' / 'Page updated.'</li> <li>item_link - Title for a navigation link block variation. Default is 'Post Link' / 'Page Link'.</li> <li>item_link_description - Description for a navigation link block variation. Default is 'A link to a post.' / 'A link to a page.'</li> </ul> Above, the first default value is for non-hierarchical post types (like posts) and the second one is for hierarchical post types (like pages). Note: To set labels used in post type admin notices, see the 'post_updated_messages' filter.
Parameters
$post_type_objectobject|WP_Post_Type
Post type object.
Return
object
Object with all the labels as member variables.
Hooks fired · 1
One hook fires while get_post_type_labels() runs, in this order:
2099functionget_post_type_labels($post_type_object){2100$nohier_vs_hier_defaults=WP_Post_Type::get_default_labels();21012102$nohier_vs_hier_defaults['menu_name']=$nohier_vs_hier_defaults['name'];21032104$labels=_get_custom_object_labels($post_type_object,$nohier_vs_hier_defaults);21052106if(!isset($post_type_object->labels->template_name)&&isset($post_type_object->labels->singular_name)){2107/* translators: %s: Post type name. */2108$labels->template_name=sprintf(__('Single item: %s'),$post_type_object->labels->singular_name);2109}21102111$post_type=$post_type_object->name;21122113$default_labels=clone$labels;21142115/**2116 * Filters the labels of a specific post type.2117 *2118 * The dynamic portion of the hook name, `$post_type`, refers to2119 * the post type slug.2120 *2121 * Possible hook names include:2122 *2123 * - `post_type_labels_post`2124 * - `post_type_labels_page`2125 * - `post_type_labels_attachment`2126 *2127 * @since 3.5.02128 *2129 * @see get_post_type_labels() for the full list of labels.2130 *2131 * @param object $labels Object with labels for the post type as member variables.2132 */2133$labels=apply_filters("post_type_labels_{$post_type}",$labels);21342135// Ensure that the filtered labels contain all required default values.2136$labels=(object)array_merge((array)$default_labels,(array)$labels);21372138return$labels;2139}
History
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.7.0
Restored pre-6.4.0 defaults for the add_new label and updated documentation. Updated core usage to reference add_new_item.from the docblock
6.6.0
Added the template_name label.from the docblock
6.4.0
Changed default values for the add_new label to include the type of content. This matches add_new_item and provides more context for better accessibility.from the docblock
6.3.0
Added the item_trashed label.from the docblock
5.8.0
Added the item_link and item_link_description labels.from the docblock
5.7.0
Added the filter_by_date label.from the docblock
5.0.0
Added the item_published, item_published_privately, item_reverted_to_draft, item_scheduled, and item_updated labels.from the docblock
4.7.0
Added the view_items and attributes labels.from the docblock
4.6.0
Converted the $post_type parameter to accept a WP_Post_Type object.from the docblock
4.4.0
Added the archives, insert_into_item, uploaded_to_this_item, filter_items_list, items_list_navigation, and items_list labels.from the docblock
4.3.0
Added the featured_image, set_featured_image, remove_featured_image, and use_featured_image labels.from the docblock
3.0.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.