get_the_term_list

The timeline below displays how wordpress function get_the_term_list has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.9

/**
 * Retrieves a post's terms as a list with specified format.
 *
 * Terms are linked to their respective term listing pages.
 *
 * @since 2.5.0
 *
 * @param int    $post_id  Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before   Optional. String to use before the terms. Default empty.
 * @param string $sep      Optional. String to use between the terms. Default empty.
 * @param string $after    Optional. String to use after the terms. Default empty.
 * @return string|false|WP_Error A list of terms on success, false if there are no terms,
 *                               WP_Error on failure.
 */
function get_the_term_list($post_id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($post_id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    $links = array();
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    /**
     * Filters the term links for a given taxonomy.
     *
     * The dynamic portion of the hook name, `$taxonomy`, refers
     * to the taxonomy slug.
     *
     * Possible hook names include:
     *
     *  - `term_links-category`
     *  - `term_links-post_tag`
     *  - `term_links-post_format`
     *
     * @since 2.5.0
     *
     * @param string[] $links An array of term links.
     */
    $term_links = apply_filters("term_links-{$taxonomy}", $links);
    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
    return $before . implode($sep, $term_links) . $after;
}

WordPress Version: 5.6

/**
 * Retrieves a post's terms as a list with specified format.
 *
 * Terms are linked to their respective term listing pages.
 *
 * @since 2.5.0
 *
 * @param int    $post_id  Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before   Optional. String to use before the terms. Default empty.
 * @param string $sep      Optional. String to use between the terms. Default empty.
 * @param string $after    Optional. String to use after the terms. Default empty.
 * @return string|false|WP_Error A list of terms on success, false if there are no terms,
 *                               WP_Error on failure.
 */
function get_the_term_list($post_id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($post_id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    $links = array();
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    /**
     * Filters the term links for a given taxonomy.
     *
     * The dynamic portion of the filter name, `$taxonomy`, refers
     * to the taxonomy slug.
     *
     * @since 2.5.0
     *
     * @param string[] $links An array of term links.
     */
    $term_links = apply_filters("term_links-{$taxonomy}", $links);
    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
    return $before . implode($sep, $term_links) . $after;
}

WordPress Version: 5.5

/**
 * Retrieves a post's terms as a list with specified format.
 *
 * Terms are linked to their respective term listing pages.
 *
 * @since 2.5.0
 *
 * @param int    $post_id  Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before   Optional. String to use before the terms. Default empty.
 * @param string $sep      Optional. String to use between the terms. Default empty.
 * @param string $after    Optional. String to use after the terms. Default empty.
 * @return string|false|WP_Error A list of terms on success, false if there are no terms,
 *                               WP_Error on failure.
 */
function get_the_term_list($post_id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($post_id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    $links = array();
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    /**
     * Filters the term links for a given taxonomy.
     *
     * The dynamic portion of the filter name, `$taxonomy`, refers
     * to the taxonomy slug.
     *
     * @since 2.5.0
     *
     * @param string[] $links An array of term links.
     */
    $term_links = apply_filters("term_links-{$taxonomy}", $links);
    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
    return $before . join($sep, $term_links) . $after;
}

WordPress Version: 5.4

/**
 * Retrieve a post's terms as a list with specified format.
 *
 * @since 2.5.0
 *
 * @param int    $id       Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before   Optional. Before list.
 * @param string $sep      Optional. Separate items using this.
 * @param string $after    Optional. After list.
 * @return string|false|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
 */
function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    $links = array();
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    /**
     * Filters the term links for a given taxonomy.
     *
     * The dynamic portion of the filter name, `$taxonomy`, refers
     * to the taxonomy slug.
     *
     * @since 2.5.0
     *
     * @param string[] $links An array of term links.
     */
    $term_links = apply_filters("term_links-{$taxonomy}", $links);
    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
    return $before . join($sep, $term_links) . $after;
}

WordPress Version: 5.3

/**
 * Retrieve a post's terms as a list with specified format.
 *
 * @since 2.5.0
 *
 * @param int $id Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before Optional. Before list.
 * @param string $sep Optional. Separate items using this.
 * @param string $after Optional. After list.
 * @return string|false|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
 */
function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    $links = array();
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    /**
     * Filters the term links for a given taxonomy.
     *
     * The dynamic portion of the filter name, `$taxonomy`, refers
     * to the taxonomy slug.
     *
     * @since 2.5.0
     *
     * @param string[] $links An array of term links.
     */
    $term_links = apply_filters("term_links-{$taxonomy}", $links);
    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
    return $before . join($sep, $term_links) . $after;
}

WordPress Version: 5.1

/**
 * Retrieve a post's terms as a list with specified format.
 *
 * @since 2.5.0
 *
 * @param int $id Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before Optional. Before list.
 * @param string $sep Optional. Separate items using this.
 * @param string $after Optional. After list.
 * @return string|false|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
 */
function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    $links = array();
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    /**
     * Filters the term links for a given taxonomy.
     *
     * The dynamic portion of the filter name, `$taxonomy`, refers
     * to the taxonomy slug.
     *
     * @since 2.5.0
     *
     * @param string[] $links An array of term links.
     */
    $term_links = apply_filters("term_links-{$taxonomy}", $links);
    return $before . join($sep, $term_links) . $after;
}

WordPress Version: 4.6

/**
 * Retrieve a post's terms as a list with specified format.
 *
 * @since 2.5.0
 *
 * @param int $id Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before Optional. Before list.
 * @param string $sep Optional. Separate items using this.
 * @param string $after Optional. After list.
 * @return string|false|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
 */
function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    $links = array();
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    /**
     * Filters the term links for a given taxonomy.
     *
     * The dynamic portion of the filter name, `$taxonomy`, refers
     * to the taxonomy slug.
     *
     * @since 2.5.0
     *
     * @param array $links An array of term links.
     */
    $term_links = apply_filters("term_links-{$taxonomy}", $links);
    return $before . join($sep, $term_links) . $after;
}

WordPress Version: 4.3

/**
 * Retrieve a post's terms as a list with specified format.
 *
 * @since 2.5.0
 *
 * @param int $id Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before Optional. Before list.
 * @param string $sep Optional. Separate items using this.
 * @param string $after Optional. After list.
 * @return string|false|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
 */
function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    $links = array();
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    /**
     * Filter the term links for a given taxonomy.
     *
     * The dynamic portion of the filter name, `$taxonomy`, refers
     * to the taxonomy slug.
     *
     * @since 2.5.0
     *
     * @param array $links An array of term links.
     */
    $term_links = apply_filters("term_links-{$taxonomy}", $links);
    return $before . join($sep, $term_links) . $after;
}

WordPress Version: 4.2

/**
 * Retrieve a post's terms as a list with specified format.
 *
 * @since 2.5.0
 *
 * @param int $id Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before Optional. Before list.
 * @param string $sep Optional. Separate items using this.
 * @param string $after Optional. After list.
 * @return string|bool|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
 */
function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    $links = array();
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    /**
     * Filter the term links for a given taxonomy.
     *
     * The dynamic portion of the filter name, `$taxonomy`, refers
     * to the taxonomy slug.
     *
     * @since 2.5.0
     *
     * @param array $links An array of term links.
     */
    $term_links = apply_filters("term_links-{$taxonomy}", $links);
    return $before . join($sep, $term_links) . $after;
}

WordPress Version: 4.1

/**
 * Retrieve a post's terms as a list with specified format.
 *
 * @since 2.5.0
 *
 * @param int $id Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before Optional. Before list.
 * @param string $sep Optional. Separate items using this.
 * @param string $after Optional. After list.
 * @return string|bool|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
 */
function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $term_links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    /**
     * Filter the term links for a given taxonomy.
     *
     * The dynamic portion of the filter name, `$taxonomy`, refers
     * to the taxonomy slug.
     *
     * @since 2.5.0
     *
     * @param array $term_links An array of term links.
     */
    $term_links = apply_filters("term_links-{$taxonomy}", $term_links);
    return $before . join($sep, $term_links) . $after;
}

WordPress Version: 4.0

/**
 * Retrieve a post's terms as a list with specified format.
 *
 * @since 2.5.0
 *
 * @param int $id Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before Optional. Before list.
 * @param string $sep Optional. Separate items using this.
 * @param string $after Optional. After list.
 * @return string|bool|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
 */
function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $term_links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    /**
     * Filter the term links for a given taxonomy.
     *
     * The dynamic portion of the filter name, $taxonomy, refers
     * to the taxonomy slug.
     *
     * @since 2.5.0
     *
     * @param array $term_links An array of term links.
     */
    $term_links = apply_filters("term_links-{$taxonomy}", $term_links);
    return $before . join($sep, $term_links) . $after;
}

WordPress Version: 3.9

/**
 * Retrieve a post's terms as a list with specified format.
 *
 * @since 2.5.0
 *
 * @param int $id Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before Optional. Before list.
 * @param string $sep Optional. Separate items using this.
 * @param string $after Optional. After list.
 * @return string|bool|WP_Error A list of terms on success, false or WP_Error on failure.
 */
function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $term_links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    /**
     * Filter the term links for a given taxonomy.
     *
     * The dynamic portion of the filter name, $taxonomy, refers
     * to the taxonomy slug.
     *
     * @since 2.5.0
     *
     * @param array $term_links An array of term links.
     */
    $term_links = apply_filters("term_links-{$taxonomy}", $term_links);
    return $before . join($sep, $term_links) . $after;
}

WordPress Version: 3.7

/**
 * Retrieve a post's terms as a list with specified format.
 *
 * @since 2.5.0
 *
 * @param int $id Post ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $before Optional. Before list.
 * @param string $sep Optional. Separate items using this.
 * @param string $after Optional. After list.
 * @return string|bool|WP_Error A list of terms on success, false or WP_Error on failure.
 */
function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '')
{
    $terms = get_the_terms($id, $taxonomy);
    if (is_wp_error($terms)) {
        return $terms;
    }
    if (empty($terms)) {
        return false;
    }
    foreach ($terms as $term) {
        $link = get_term_link($term, $taxonomy);
        if (is_wp_error($link)) {
            return $link;
        }
        $term_links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
    }
    $term_links = apply_filters("term_links-{$taxonomy}", $term_links);
    return $before . join($sep, $term_links) . $after;
}