the_taxonomies()WP 2.5.0

Display links to taxonomy terms of the current post. Used inside WordPress loop

You can also use this function on a separate post page to display the taxonomy elements the post refers to.

1 time — 0.009228 sec (very slow) | 50000 times — 51.10 sec (very slow) | PHP 7.1.2, WP 4.7.3

No Hooks.

Return

null. Displays a list of links to taxonomy items (terms), of the current post.

Usage

<?php the_taxonomies( $args ); ?>
$args(array)

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.

Default: array() - presets

  • post(int|WP_Post)
    Post ID or WP_Post object to get taxonomies of.
    Default: current post

  • before(string)
    Displays before the taxonomies.
    Default: empty string

  • after(string)
    Displays after the taxonomies.
    Default: empty string

  • sep(string)
    Separates each taxonomy.
    Default: space

  • template(string)
    Template for list output. Where %s is the name of the taxonomy and %l is the list of items in the format specified in the parameter $term_template.
    Default: '%s: %l.'

  • term_template(string)
    The output format of each taxonomy element.
    Default: '<a href="%1$s">%2$s</a>'

Examples

0

#1 Output demonstration

Example output for regular posts that are attached to headings and tags.

<?php the_taxonomies('post=119'); ?>

Will displays:

Topics: <a href="Link">Code</a>. Tags: <a href="Link">Hacks</a> and <a href="Link">Hooks</a>.
0

#2 Demonstration of output for custom taxonomies

<?php the_taxonomies('post=7363'); ?>

It will:

Taxonomy: <a href="Reference">Code</a>. Another taxonomy: <a href="URL">Haki</a> and <a href="URL">Huki</a>.
0

#3 Let's display the list by wrapping it in the <div> tag:

<?php
the_taxonomies( array(
	'post'   =>119,
	'before' =>'<div class="foo">',
	'after'  =>'</div>'
) );
?>

It will:

<div class="foo">
	Topics: <a href="URL">code</a>. Tags: <a href="URL">loop</a> and <a href="URL">Beginners</a>.
</div>

Changelog

Since 2.5.0 Introduced.

the_taxonomies() code WP 6.7.1

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'];
}