WordPress get_the_term_list() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template tag

Definition

In WordPress, get_the_term_list() returns the terms of a post for one taxonomy. Each term is a link to its archive page.

It returns an HTML string. It does not print it. If you want to print the list straight away, use the_terms().

Syntax

Pass the post ID and the taxonomy name. The text before, between, and after is optional.

WordPress
get_the_term_list( get_the_ID(), 'category' );
get_the_term_list( get_the_ID(), 'post_tag', 'Tags: ', ', ', '' );
CallWhat it does
get_the_term_list( $post_id, 'category' )Returns the categories of a post as links.
get_the_term_list( $post_id, 'post_tag', 'Tags: ', ', ' )Adds text before the list and a comma between links.
get_the_term_list( $post_id, 'genre' )Works with a custom taxonomy such as genre.

Always test the result. It can be false or a WP_Error object.

Full declaration
WordPress
get_the_term_list( int $post_id, string $taxonomy, string $before = '', string $sep = '', string $after = '' ): string|false|WP_Error

Parameters

ParameterDescription
$post_idRequired. The post ID. Use get_the_ID() inside The Loop.
$taxonomyRequired. The taxonomy name, such as category, post_tag, or a custom name.
$beforeOptional. Text placed before the list. Default is an empty string.
$sepOptional. Text placed between each term. Default is an empty string.
$afterOptional. Text placed after the list. Default is an empty string.

Return Value

Return ValueDescription
stringHTML links to the terms, joined by the separator.
falseThe post has no terms in this taxonomy.
WP_ErrorThe taxonomy does not exist.

WordPress Examples

Three short theme examples. Each one has a sample output.

Example 1 — Categories as links

Get the categories of the current post.

WordPress
<?php
$list = get_the_term_list( get_the_ID(), 'category', '', ', ', '' );
echo $list;
?>

How It Works

  1. get_the_ID() gives the current post ID.
  2. 'category' is the taxonomy name.
  3. The comma is placed between the links.

Example 2 — Custom taxonomy with a label

Add a label and wrap the result in a paragraph.

WordPress
<?php
$genres = get_the_term_list( get_the_ID(), 'genre', 'Genres: ', ', ', '' );
if ( $genres ) {
  echo '<p>' . $genres . '</p>';
}
?>

How It Works

  1. genre is a custom taxonomy you registered.
  2. Genres: is printed before the links.
  3. The if stops an empty paragraph when there are no terms.

Example 3 — Check false and WP_Error

Test the result before you print it.

WordPress
<?php
$tags = get_the_term_list( get_the_ID(), 'post_tag', 'Tags: ', ', ', '' );
if ( $tags && ! is_wp_error( $tags ) ) {
  echo '<p class="tags">' . $tags . '</p>';
}
?>

How It Works

  1. $tags is true only when links were returned.
  2. is_wp_error() catches a wrong taxonomy name.
  3. The paragraph is printed only when the result is safe to use.

Frequently Asked Questions

It returns an HTML string of linked terms. It can also return false when there are no terms, or a WP_Error when the taxonomy does not exist.
get_the_term_list() returns the string. the_terms() prints it.
Yes. Pass the taxonomy name as the second argument, for example 'genre'.
You only need a post ID. Inside The Loop, use get_the_ID(). Outside The Loop, pass any post ID.
Use get_the_terms() and loop over the term objects. Then read each name with $term->name.

Next: single_cat_title()

Print or return the title (name) of the current category archive.

single_cat_title() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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