get_taxonomy_labels()WP 3.0.0

Builds/returns an object with all the headers of the specified taxonomy.

This is a helper function. It is needed to fill in the missing headers in the taxonomy description. For example, if the header for 'not_found' was not specified, it will be replaced with $tax->no_tagcloud. Use in the function register_taxonomy().

For a description of the headers that are specified in the array when registering a taxonomy, see the description of the labels parameter in the function register_taxonomy().

Returns

Object. An object with the taxonomy headers. The basic default values are set for all taxonomies, with default values differing for hierarchical and non-hierarchical taxonomies.

Possible values of the array:

name
The name of the taxonomy, usually in plural.
By default _x( 'Post Tags', 'taxonomy general name' ) or _x( 'Categories', 'taxonomy general name' );
singular_name
The name for a single item of this taxonomy.
By default _x( 'Post Tag', 'taxonomy singular name' ) or _x( 'Category', 'taxonomy singular name' );
menu_name
Text for the menu name. This string denotes the name for menu items.
By default the value of the name parameter.
search_items
Text for searching a taxonomy item.
By default __( 'Search Tags' ) or __( 'Search Categories' ).
popular_items
Text for the block of popular items. __( 'Popular Tags' ) or null.
all_items
Text for all items. __( 'All Tags' ) or __( 'All Categories' );
parent_item
Text for the parent item of the taxonomy. This argument is not used for non-hierarchical taxonomies.
By default null or __( 'Parent Category' );
parent_item_colon
Text for the parent item of the taxonomy, the same as parent_item but with a colon at the end.
By default none or __( 'Parent Category:' );
edit_item
Text for editing an item.
By default __( 'Edit Tag' ) or __( 'Edit Category' );
update_item
Text for updating an item.
By default __( 'Update Tag' ) or __( 'Update Category' );
add_new_item
Text for adding a new taxonomy item.
By default __( 'Add New Tag' ) or __( 'Add New Category' );
view_item
Text for viewing a taxonomy term.
By default: "View Tag", "View Category". Used for example in the admin bar (toolbar).
new_item_name
Text for creating a new taxonomy item.
By default __( 'New Tag Name' ) or __( 'New Category Name' );
separate_items_with_commas
Text describing that items should be separated by commas (for the blog in the admin). Does not work for hierarchical types.
By default __( 'Separate tags with commas' ) or null;
add_or_remove_items
Text for "adding or removing an item", which is used in the admin block when JavaScript is disabled. Does not apply to hierarchical taxonomies.
By default __( 'Add or remove tags' ) or null;
choose_from_most_used
Text for the blog when editing a post "choose from the most used". Not used for hierarchical taxonomies.
By default __( 'Choose from the most used tags' ) or null;
popular_items
Text for searching popular terms. This parameter is not used for hierarchical taxonomies.
By default: "Popular Tags" or null.
separate_items_with_commas
Text stating that terms (tags) should be separated by commas. Not used for hierarchical taxonomies.
By default: "Separate tags with commas" or null.
add_or_remove_items
Text for adding or removing terms. Not used for hierarchical types.
By default: "Add or remove tags" or null.
choose_from_most_used
Text "Choose from the most used". Not used for hierarchical types.
not_found
Text "not found", which is displayed if no term was found when clicking on frequently used.
no_terms
Used in post and media tables.
By default 'No tags'/'No categories'.
items_list_navigation
Text for the pagination table, for the hidden header.
items_list
Text for the hidden header of the table.
most_used(WP 4.9)
Text for the "Most Used" tab.
back_to_items(WP 4.9)
Text that will be shown after updating the term.
filter_by_item(WP 5.7)
Used only for hierarchical taxonomies, in the admin, in the posts list table.
By default: 'Filter by category'.
item_link(WP 5.8)
Text for the link, for example: 'Tag Link' or 'Category Link'.
item_link_description(WP 5.8)
Text for the link description, for example: 'A link to a tag.' or 'A link to a category.'.
name_field_description(WP 5.9)
Description for the Name field on the term edit page (Edit Tags screen).
By default: 'The name is how it appears on your site.'
slug_field_description(WP 5.9)
Description for the Slug field on the term edit page (Edit Tags screen).
By default: 'The slug is a URL-friendly version of the name. Usually contains only lowercase letters, numbers, and hyphens.'.
parent_field_description(WP 5.9)
Description for the Parent field on the term edit page (Edit Tags screen).
By default: 'Assign a parent term to create a hierarchy. For example, the term Jazz is the parent of the terms Bebop and Big Band.'.
desc_field_description(WP 5.9)
Description for the Description field on the term edit page (Edit Tags screen).
By default: 'By default, the description is not displayed, but some themes may show it.'.

Usage

get_taxonomy_labels( $tax );
$tax(object/WP_Taxonomy) (required)
The taxonomy object.

Examples

0

#1 Demo

$tax = get_taxonomy( 'category' );

$labels = get_taxonomy_labels( $tax );

print_r( $labels );

/* We get:
stdClass Object
(
	[name] => Categories
	[singular_name] => Category
	[search_items] => Search categories
	[popular_items] =>
	[all_items] => All categories
	[parent_item] => Parent category
	[parent_item_colon] => Parent category:
	[edit_item] => Change categories
	[view_item] => View categories
	[update_item] => Update categories
	[add_new_item] => Add new categories
	[new_item_name] => New category name
	[separate_items_with_commas] =>
	[add_or_remove_items] =>
	[choose_from_most_used] =>
	[not_found] => No categories found.
	[no_terms] => No categories
	[menu_name] => Categories                   // defaults to `name` property. Used for the tab in the admin menu.
	[name_admin_bar] => category
)
*/

Changelog

Since 3.0.0 Introduced.
Since 4.3.0 Added the no_terms label.
Since 4.4.0 Added the items_list_navigation and items_list labels.
Since 4.9.0 Added the most_used and back_to_items labels.
Since 5.7.0 Added the filter_by_item label.
Since 5.8.0 Added the item_link and item_link_description labels.
Since 5.9.0 Added the name_field_description, slug_field_description, parent_field_description, and desc_field_description labels.
Since 6.6.0 Added the template_name label.

get_taxonomy_labels() code WP 6.9.1

function get_taxonomy_labels( $tax ) {
	$tax->labels = (array) $tax->labels;

	if ( isset( $tax->helps ) && empty( $tax->labels['separate_items_with_commas'] ) ) {
		$tax->labels['separate_items_with_commas'] = $tax->helps;
	}

	if ( isset( $tax->no_tagcloud ) && empty( $tax->labels['not_found'] ) ) {
		$tax->labels['not_found'] = $tax->no_tagcloud;
	}

	$nohier_vs_hier_defaults = WP_Taxonomy::get_default_labels();

	$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];

	$labels = _get_custom_object_labels( $tax, $nohier_vs_hier_defaults );

	if ( ! isset( $tax->labels->template_name ) && isset( $labels->singular_name ) ) {
		/* translators: %s: Taxonomy name. */
		$labels->template_name = sprintf( _x( '%s Archives', 'taxonomy template name' ), $labels->singular_name );
	}

	$taxonomy = $tax->name;

	$default_labels = clone $labels;

	/**
	 * Filters the labels of a specific taxonomy.
	 *
	 * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
	 *
	 * Possible hook names include:
	 *
	 *  - `taxonomy_labels_category`
	 *  - `taxonomy_labels_post_tag`
	 *
	 * @since 4.4.0
	 *
	 * @see get_taxonomy_labels() for the full list of taxonomy labels.
	 *
	 * @param object $labels Object with labels for the taxonomy as member variables.
	 */
	$labels = apply_filters( "taxonomy_labels_{$taxonomy}", $labels );

	// Ensure that the filtered labels contain all required default values.
	$labels = (object) array_merge( (array) $default_labels, (array) $labels );

	return $labels;
}