WordPress the_taxonomies() Function

Definition
In WordPress, the_taxonomies() prints every taxonomy of a post with its terms. For example: Categories: News. Tags: PHP.
It prints the text. It does not return it. It is a quick way to show categories, tags, and custom taxonomies together.
Syntax
Call it with no arguments, or pass an array to change the post or the text around the list.
the_taxonomies();
the_taxonomies( array( 'post' => 42 ) );
the_taxonomies( array( 'before' => '<p>', 'after' => '</p>' ) );
| Call | What it does |
|---|
the_taxonomies() | Prints all taxonomies of the current post. |
the_taxonomies( array( 'post' => 42 ) ) | Prints the taxonomies of the post with ID 42. |
the_taxonomies( array( 'before' => '<p>', 'after' => '</p>' ) ) | Wraps the text in a paragraph. |
Only taxonomies that have terms for the post are shown.
Full declaration
the_taxonomies( array $args = array() ): void
Parameters
| Parameter | Description |
|---|
$args['post'] | Optional. Post ID or object. Default is the current post. |
$args['before'] | Optional. Text placed before the whole output. Default is an empty string. |
$args['sep'] | Optional. Text placed between taxonomies. Default is a space. |
$args['after'] | Optional. Text placed after the whole output. Default is an empty string. |
$args['template'] | Optional. How each taxonomy is written. Default is %s: %l. |
$args['term_template'] | Optional. How each term link is written. Default is a link to the term archive. |
Return Value
| Return Value | Description |
|---|
| void | Nothing is returned. The function prints the taxonomies and their terms. |
WordPress Examples
Three short theme examples. Each one has a sample output.
Example 1 — Default output
Print all taxonomies of the current post.
<?php the_taxonomies(); ?>
Categories: <a href="https://example.com/category/news/">News</a>. Tags: <a href="https://example.com/tag/php/">PHP</a> and <a href="https://example.com/tag/wordpress/">WordPress</a>.
How It Works
- WordPress finds every taxonomy used by the post.
- Each taxonomy label is followed by its term links.
- Two terms are joined with the word and.
Example 2 — Wrapped in HTML
Wrap the output in a paragraph and change the separator.
<?php
the_taxonomies( array(
'before' => '<p class="post-terms">',
'sep' => ' | ',
'after' => '</p>',
) );
?>
<p class="post-terms">Categories: <a href="https://example.com/category/news/">News</a>. | Tags: <a href="https://example.com/tag/php/">PHP</a>.</p>
How It Works
before and after create the paragraph.sep goes between the taxonomy groups.- Style the
post-terms class in your CSS.
Example 3 — Specific post
Print the taxonomies of a post by its ID.
<?php the_taxonomies( array( 'post' => 42 ) ); ?>
Categories: <a href="https://example.com/category/tips/">Tips</a>. Tags: <a href="https://example.com/tag/css/">CSS</a>.
How It Works
'post' => 42 picks the post.- The rest works the same as the default output.
- Use this when you are outside The Loop.
Frequently Asked Questions
It prints all taxonomies of a post with their terms. For example: Categories: News. Tags: PHP.
Yes. It shows every taxonomy that is attached to the post type and has terms for the post.
the_taxonomies() prints all taxonomies together. the_terms() prints the terms of one taxonomy that you choose.
Yes. Use the template and term_template arguments for custom text and links.
No. It prints the text. Use get_the_taxonomies() if you want an array.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful