Builds an object with all taxonomy labels out of a taxonomy object.
$taxWP_Taxonomyrequired
name string$tax->label. Default 'Tags'/'Categories'.singular_name string'Tag'/'Category'.search_items string'/'Search Categories’.popular_items stringall_items string'/'All Categories’.parent_item stringparent_item_colon stringparent_item, but with colon : in the end.name_field_description stringslug_field_description stringparent_field_description stringdesc_field_description stringedit_item string'/'Edit Category’.view_item string'/'View Category’.update_item string'/'Update Category’.add_new_item string'/'Add New Category’.new_item_name string'/'New Category Name’.template_name string'/'Category Archives’.separate_items_with_commas stringadd_or_remove_items stringchoose_from_most_used stringnot_found string'/'No categories found’, used in the meta box and taxonomy list table.no_terms string'/'No categories’, used in the posts and media list tables.filter_by_item stringitems_list_navigation stringitems_list stringmost_used stringback_to_items stringitem_link string'/'Category Link’.item_link_description string'/'A link to a category’.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;
}
Filters the labels of a specific taxonomy.
| Version | Description |
|---|---|
| 6.6.0 | Added the template_name label. |
| 5.9.0 | Added the name_field_description, slug_field_description, parent_field_description, and desc_field_description labels. |
| 5.8.0 | Added the item_link and item_link_description labels. |
| 5.7.0 | Added the filter_by_item label. |
| 4.9.0 | Added the most_used and back_to_items labels. |
| 4.4.0 | Added the items_list_navigation and items_list labels. |
| 4.3.0 | Added the no_terms label. |
| 3.0.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_taxonomy_labels