taxonomy_labels_(taxonomy)
Allows you to change the labels (headings) of a specified taxonomy, such as categories or tags.
$taxonomy in the filter name is the taxonomy slug specified as the first argument of register_taxonomy().
To change post type labels, for example to replace "Posts" with "Products", see:
- How to change “Posts” to another word in WordPress.
- post_type_labels_(post_type) — a similar hook for post types.
Usage
add_filter( 'taxonomy_labels_(taxonomy)', 'wp_kama_taxonomy_labels_filter' );
/**
* Function for `taxonomy_labels_(taxonomy)` filter-hook.
*
* @param object $labels Object with labels for the taxonomy as member variables.
*
* @return object
*/
function wp_kama_taxonomy_labels_filter( $labels ){
// filter...
return $labels;
}
- $labels(object)
Object containing the translated taxonomy labels.
The
$labelsvariable contains data like this: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] => Edit Category [view_item] => View Category [update_item] => Update Category [add_new_item] => Add New Category [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 [items_list_navigation] => Categories list navigation [items_list] => Categories list [most_used] => Most Used [back_to_items] => ← Back to Categories [menu_name] => Categories [name_admin_bar] => category )
Any label properties not changed by this hook are taken from the original object. WordPress core does this as follows:
// Create a duplicate of the original labels.
$default_labels = clone $labels;
// Pass the labels through the filter.
$labels = apply_filters( "taxonomy_labels_{$taxonomy}", $labels );
// Merge the labels with the originals, replacing matching values.
$labels = (object) array_merge( (array) $default_labels, (array) $labels );
Because custom and original labels are always merged with replacement, the data passed to the filter is rarely needed except for debugging.
Examples
#1 Change the word "Categories" to something else
## Change the labels of the Categories taxonomy.
add_filter( 'taxonomy_labels_'.'category', 'change_labels_category' );
function change_labels_category( $labels ) {
// Store the labels to change in an array for convenience.
$my_labels = array(
'name' => 'Product Types',
'singular_name' => 'Product Type',
'search_items' => 'Search Product Types',
'all_items' => 'All Product Types',
'parent_item' => 'Parent Product Type',
'parent_item_colon' => 'Parent Product Type:',
'edit_item' => 'Edit Product Type',
'view_item' => 'View Product Type',
'update_item' => 'Update Product Type',
'add_new_item' => 'Add New Product Type',
'new_item_name' => 'New Product Type Name',
'not_found' => 'No product types found.',
'no_terms' => 'No product types',
'items_list_navigation' => 'Product types list navigation',
'items_list' => 'Product types list',
'back_to_items' => '← Back to product types',
'menu_name' => 'Product Types',
);
return $my_labels;
}
Changelog
| Since 4.4.0 | Introduced. |
Where the hook is called
wp-includes/taxonomy.php 749
$labels = apply_filters( "taxonomy_labels_{$taxonomy}", $labels );
