Displays the taxonomies of a post with available options.
Description
This function can be used within the loop to display the taxonomies for a post without specifying the Post ID. You can also use it outside the Loop to display the taxonomies for a specific post.
Parameters
$argsarrayoptional- Arguments about which post to use and how to format the output. Shares all of the arguments supported by get_the_taxonomies() , in addition to the following.
postint|WP_PostPost ID or object to get taxonomies of. Default current post.beforestringDisplays before the taxonomies. Default empty string.sepstringSeparates each taxonomy. Default is a space.afterstringDisplays after the taxonomies. Default empty string.
More Arguments from get_the_taxonomies( … $args )
Arguments about how to format the list of taxonomies.
templatestringTemplate for displaying a taxonomy label and list of terms.
Default is "Label: Terms."term_templatestringTemplate for displaying a single term in the list. Default is the term name linked to its archive.
Default:
array()
Source
function the_taxonomies( $args = array() ) {
$defaults = array(
'post' => 0,
'before' => '',
'sep' => ' ',
'after' => '',
);
$parsed_args = wp_parse_args( $args, $defaults );
echo $parsed_args['before'] . implode( $parsed_args['sep'], get_the_taxonomies( $parsed_args['post'], $parsed_args ) ) . $parsed_args['after'];
}
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
This can be used in a theme to support all taxonomies easily.
Example