Using WordPress ‘get_taxonomy_labels()’ PHP function

The get_taxonomy_labels() WordPress PHP function builds an object with all taxonomy labels out of a taxonomy object.

Usage

$taxonomy_labels = get_taxonomy_labels($tax);

Input:

$tax = get_taxonomy('category');

Output:
An object with taxonomy labels for the ‘category’ taxonomy.

Parameters

  • $tax (WP_Taxonomy): Required. Taxonomy object.

More information

See WordPress Developer Resources: get_taxonomy_labels()

Examples

Displaying Taxonomy Labels

Displaying taxonomy labels for a custom taxonomy called ‘movie_genre’:

$tax = get_taxonomy('movie_genre');
$taxonomy_labels = get_taxonomy_labels($tax);
echo "Singular name: " . $taxonomy_labels->singular_name;
echo "Plural name: " . $taxonomy_labels->name;

Get Menu Name of Taxonomy

Getting the menu name of a taxonomy called ‘product_type’:

$tax = get_taxonomy('product_type');
$taxonomy_labels = get_taxonomy_labels($tax);
echo "Menu name: " . $taxonomy_labels->menu_name;

Displaying All Taxonomy Labels

Displaying all taxonomy labels for a taxonomy called ‘location’:

$tax = get_taxonomy('location');
$taxonomy_labels = get_taxonomy_labels($tax);

foreach ($taxonomy_labels as $key => $label) {
    echo "$key: $label" . PHP_EOL;
}

Get Taxonomy Labels for Tags

Getting taxonomy labels for default ‘post_tag’ taxonomy:

$tax = get_taxonomy('post_tag');
$taxonomy_labels = get_taxonomy_labels($tax);
echo "Singular name: " . $taxonomy_labels->singular_name;
echo "Plural name: " . $taxonomy_labels->name;

Displaying Taxonomy Labels for a Hierarchical Taxonomy

Displaying taxonomy labels for a hierarchical taxonomy called ‘department’:

$tax = get_taxonomy('department');
$taxonomy_labels = get_taxonomy_labels($tax);

echo "Add New: " . $taxonomy_labels->add_new_item;
echo "Parent Item: " . $taxonomy_labels->parent_item;