get_term_link

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

WordPress Version: 6.1

/**
 * Generates a permalink for a taxonomy term archive.
 *
 * @since 2.5.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param WP_Term|int|string $term     The term object, ID, or slug whose link will be retrieved.
 * @param string             $taxonomy Optional. Taxonomy. Default empty.
 * @return string|WP_Error URL of the taxonomy term archive on success, WP_Error if term does not exist.
 */
function get_term_link($term, $taxonomy = '')
{
    global $wp_rewrite;
    if (!is_object($term)) {
        if (is_int($term)) {
            $term = get_term($term, $taxonomy);
        } else {
            $term = get_term_by('slug', $term, $taxonomy);
        }
    }
    if (!is_object($term)) {
        $term = new WP_Error('invalid_term', __('Empty Term.'));
    }
    if (is_wp_error($term)) {
        return $term;
    }
    $taxonomy = $term->taxonomy;
    $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    /**
     * Filters the permalink structure for a term before token replacement occurs.
     *
     * @since 4.9.0
     *
     * @param string  $termlink The permalink structure for the term's taxonomy.
     * @param WP_Term $term     The term object.
     */
    $termlink = apply_filters('pre_term_link', $termlink, $term);
    $slug = $term->slug;
    $t = get_taxonomy($taxonomy);
    if (empty($termlink)) {
        if ('category' === $taxonomy) {
            $termlink = '?cat=' . $term->term_id;
        } elseif ($t->query_var) {
            $termlink = "?{$t->query_var}={$slug}";
        } else {
            $termlink = "?taxonomy={$taxonomy}&term={$slug}";
        }
        $termlink = home_url($termlink);
    } else {
        if (!empty($t->rewrite['hierarchical'])) {
            $hierarchical_slugs = array();
            $ancestors = get_ancestors($term->term_id, $taxonomy, 'taxonomy');
            foreach ((array) $ancestors as $ancestor) {
                $ancestor_term = get_term($ancestor, $taxonomy);
                $hierarchical_slugs[] = $ancestor_term->slug;
            }
            $hierarchical_slugs = array_reverse($hierarchical_slugs);
            $hierarchical_slugs[] = $slug;
            $termlink = str_replace("%{$taxonomy}%", implode('/', $hierarchical_slugs), $termlink);
        } else {
            $termlink = str_replace("%{$taxonomy}%", $slug, $termlink);
        }
        $termlink = home_url(user_trailingslashit($termlink, 'category'));
    }
    // Back compat filters.
    if ('post_tag' === $taxonomy) {
        /**
         * Filters the tag link.
         *
         * @since 2.3.0
         * @since 2.5.0 Deprecated in favor of {@see 'term_link'} filter.
         * @since 5.4.1 Restored (un-deprecated).
         *
         * @param string $termlink Tag link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('tag_link', $termlink, $term->term_id);
    } elseif ('category' === $taxonomy) {
        /**
         * Filters the category link.
         *
         * @since 1.5.0
         * @since 2.5.0 Deprecated in favor of {@see 'term_link'} filter.
         * @since 5.4.1 Restored (un-deprecated).
         *
         * @param string $termlink Category link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('category_link', $termlink, $term->term_id);
    }
    /**
     * Filters the term link.
     *
     * @since 2.5.0
     *
     * @param string  $termlink Term link URL.
     * @param WP_Term $term     Term object.
     * @param string  $taxonomy Taxonomy slug.
     */
    return apply_filters('term_link', $termlink, $term, $taxonomy);
}

WordPress Version: 5.8

/**
 * Generate a permalink for a taxonomy term archive.
 *
 * @since 2.5.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param WP_Term|int|string $term     The term object, ID, or slug whose link will be retrieved.
 * @param string             $taxonomy Optional. Taxonomy. Default empty.
 * @return string|WP_Error URL of the taxonomy term archive on success, WP_Error if term does not exist.
 */
function get_term_link($term, $taxonomy = '')
{
    global $wp_rewrite;
    if (!is_object($term)) {
        if (is_int($term)) {
            $term = get_term($term, $taxonomy);
        } else {
            $term = get_term_by('slug', $term, $taxonomy);
        }
    }
    if (!is_object($term)) {
        $term = new WP_Error('invalid_term', __('Empty Term.'));
    }
    if (is_wp_error($term)) {
        return $term;
    }
    $taxonomy = $term->taxonomy;
    $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    /**
     * Filters the permalink structure for a term before token replacement occurs.
     *
     * @since 4.9.0
     *
     * @param string  $termlink The permalink structure for the term's taxonomy.
     * @param WP_Term $term     The term object.
     */
    $termlink = apply_filters('pre_term_link', $termlink, $term);
    $slug = $term->slug;
    $t = get_taxonomy($taxonomy);
    if (empty($termlink)) {
        if ('category' === $taxonomy) {
            $termlink = '?cat=' . $term->term_id;
        } elseif ($t->query_var) {
            $termlink = "?{$t->query_var}={$slug}";
        } else {
            $termlink = "?taxonomy={$taxonomy}&term={$slug}";
        }
        $termlink = home_url($termlink);
    } else {
        if (!empty($t->rewrite['hierarchical'])) {
            $hierarchical_slugs = array();
            $ancestors = get_ancestors($term->term_id, $taxonomy, 'taxonomy');
            foreach ((array) $ancestors as $ancestor) {
                $ancestor_term = get_term($ancestor, $taxonomy);
                $hierarchical_slugs[] = $ancestor_term->slug;
            }
            $hierarchical_slugs = array_reverse($hierarchical_slugs);
            $hierarchical_slugs[] = $slug;
            $termlink = str_replace("%{$taxonomy}%", implode('/', $hierarchical_slugs), $termlink);
        } else {
            $termlink = str_replace("%{$taxonomy}%", $slug, $termlink);
        }
        $termlink = home_url(user_trailingslashit($termlink, 'category'));
    }
    // Back compat filters.
    if ('post_tag' === $taxonomy) {
        /**
         * Filters the tag link.
         *
         * @since 2.3.0
         * @since 2.5.0 Deprecated in favor of {@see 'term_link'} filter.
         * @since 5.4.1 Restored (un-deprecated).
         *
         * @param string $termlink Tag link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('tag_link', $termlink, $term->term_id);
    } elseif ('category' === $taxonomy) {
        /**
         * Filters the category link.
         *
         * @since 1.5.0
         * @since 2.5.0 Deprecated in favor of {@see 'term_link'} filter.
         * @since 5.4.1 Restored (un-deprecated).
         *
         * @param string $termlink Category link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('category_link', $termlink, $term->term_id);
    }
    /**
     * Filters the term link.
     *
     * @since 2.5.0
     *
     * @param string  $termlink Term link URL.
     * @param WP_Term $term     Term object.
     * @param string  $taxonomy Taxonomy slug.
     */
    return apply_filters('term_link', $termlink, $term, $taxonomy);
}

WordPress Version: 4.1

/**
 * Generate a permalink for a taxonomy term archive.
 *
 * @since 2.5.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param WP_Term|int|string $term     The term object, ID, or slug whose link will be retrieved.
 * @param string             $taxonomy Optional. Taxonomy. Default empty.
 * @return string|WP_Error URL of the taxonomy term archive on success, WP_Error if term does not exist.
 */
function get_term_link($term, $taxonomy = '')
{
    global $wp_rewrite;
    if (!is_object($term)) {
        if (is_int($term)) {
            $term = get_term($term, $taxonomy);
        } else {
            $term = get_term_by('slug', $term, $taxonomy);
        }
    }
    if (!is_object($term)) {
        $term = new WP_Error('invalid_term', __('Empty Term.'));
    }
    if (is_wp_error($term)) {
        return $term;
    }
    $taxonomy = $term->taxonomy;
    $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    /**
     * Filters the permalink structure for a terms before token replacement occurs.
     *
     * @since 4.9.0
     *
     * @param string  $termlink The permalink structure for the term's taxonomy.
     * @param WP_Term $term     The term object.
     */
    $termlink = apply_filters('pre_term_link', $termlink, $term);
    $slug = $term->slug;
    $t = get_taxonomy($taxonomy);
    if (empty($termlink)) {
        if ('category' === $taxonomy) {
            $termlink = '?cat=' . $term->term_id;
        } elseif ($t->query_var) {
            $termlink = "?{$t->query_var}={$slug}";
        } else {
            $termlink = "?taxonomy={$taxonomy}&term={$slug}";
        }
        $termlink = home_url($termlink);
    } else {
        if ($t->rewrite['hierarchical']) {
            $hierarchical_slugs = array();
            $ancestors = get_ancestors($term->term_id, $taxonomy, 'taxonomy');
            foreach ((array) $ancestors as $ancestor) {
                $ancestor_term = get_term($ancestor, $taxonomy);
                $hierarchical_slugs[] = $ancestor_term->slug;
            }
            $hierarchical_slugs = array_reverse($hierarchical_slugs);
            $hierarchical_slugs[] = $slug;
            $termlink = str_replace("%{$taxonomy}%", implode('/', $hierarchical_slugs), $termlink);
        } else {
            $termlink = str_replace("%{$taxonomy}%", $slug, $termlink);
        }
        $termlink = home_url(user_trailingslashit($termlink, 'category'));
    }
    // Back compat filters.
    if ('post_tag' === $taxonomy) {
        /**
         * Filters the tag link.
         *
         * @since 2.3.0
         * @since 2.5.0 Deprecated in favor of {@see 'term_link'} filter.
         * @since 5.4.1 Restored (un-deprecated).
         *
         * @param string $termlink Tag link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('tag_link', $termlink, $term->term_id);
    } elseif ('category' === $taxonomy) {
        /**
         * Filters the category link.
         *
         * @since 1.5.0
         * @since 2.5.0 Deprecated in favor of {@see 'term_link'} filter.
         * @since 5.4.1 Restored (un-deprecated).
         *
         * @param string $termlink Category link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('category_link', $termlink, $term->term_id);
    }
    /**
     * Filters the term link.
     *
     * @since 2.5.0
     *
     * @param string  $termlink Term link URL.
     * @param WP_Term $term     Term object.
     * @param string  $taxonomy Taxonomy slug.
     */
    return apply_filters('term_link', $termlink, $term, $taxonomy);
}

WordPress Version: 5.4

/**
 * Generate a permalink for a taxonomy term archive.
 *
 * @since 2.5.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param WP_Term|int|string $term     The term object, ID, or slug whose link will be retrieved.
 * @param string             $taxonomy Optional. Taxonomy. Default empty.
 * @return string|WP_Error URL of the taxonomy term archive on success, WP_Error if term does not exist.
 */
function get_term_link($term, $taxonomy = '')
{
    global $wp_rewrite;
    if (!is_object($term)) {
        if (is_int($term)) {
            $term = get_term($term, $taxonomy);
        } else {
            $term = get_term_by('slug', $term, $taxonomy);
        }
    }
    if (!is_object($term)) {
        $term = new WP_Error('invalid_term', __('Empty Term.'));
    }
    if (is_wp_error($term)) {
        return $term;
    }
    $taxonomy = $term->taxonomy;
    $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    /**
     * Filters the permalink structure for a terms before token replacement occurs.
     *
     * @since 4.9.0
     *
     * @param string  $termlink The permalink structure for the term's taxonomy.
     * @param WP_Term $term     The term object.
     */
    $termlink = apply_filters('pre_term_link', $termlink, $term);
    $slug = $term->slug;
    $t = get_taxonomy($taxonomy);
    if (empty($termlink)) {
        if ('category' === $taxonomy) {
            $termlink = '?cat=' . $term->term_id;
        } elseif ($t->query_var) {
            $termlink = "?{$t->query_var}={$slug}";
        } else {
            $termlink = "?taxonomy={$taxonomy}&term={$slug}";
        }
        $termlink = home_url($termlink);
    } else {
        if ($t->rewrite['hierarchical']) {
            $hierarchical_slugs = array();
            $ancestors = get_ancestors($term->term_id, $taxonomy, 'taxonomy');
            foreach ((array) $ancestors as $ancestor) {
                $ancestor_term = get_term($ancestor, $taxonomy);
                $hierarchical_slugs[] = $ancestor_term->slug;
            }
            $hierarchical_slugs = array_reverse($hierarchical_slugs);
            $hierarchical_slugs[] = $slug;
            $termlink = str_replace("%{$taxonomy}%", implode('/', $hierarchical_slugs), $termlink);
        } else {
            $termlink = str_replace("%{$taxonomy}%", $slug, $termlink);
        }
        $termlink = home_url(user_trailingslashit($termlink, 'category'));
    }
    // Back compat filters.
    if ('post_tag' === $taxonomy) {
        /**
         * Filters the tag link.
         *
         * @since 2.3.0
         * @deprecated 2.5.0 Use {@see 'term_link'} instead.
         *
         * @param string $termlink Tag link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters_deprecated('tag_link', array($termlink, $term->term_id), '2.5.0', 'term_link');
    } elseif ('category' === $taxonomy) {
        /**
         * Filters the category link.
         *
         * @since 1.5.0
         * @deprecated 2.5.0 Use {@see 'term_link'} instead.
         *
         * @param string $termlink Category link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters_deprecated('category_link', array($termlink, $term->term_id), '2.5.0', 'term_link');
    }
    /**
     * Filters the term link.
     *
     * @since 2.5.0
     *
     * @param string  $termlink Term link URL.
     * @param WP_Term $term     Term object.
     * @param string  $taxonomy Taxonomy slug.
     */
    return apply_filters('term_link', $termlink, $term, $taxonomy);
}

WordPress Version: 5.3

/**
 * Generate a permalink for a taxonomy term archive.
 *
 * @since 2.5.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param object|int|string $term     The term object, ID, or slug whose link will be retrieved.
 * @param string            $taxonomy Optional. Taxonomy. Default empty.
 * @return string|WP_Error URL of the taxonomy term archive on success, WP_Error if term does not exist.
 */
function get_term_link($term, $taxonomy = '')
{
    global $wp_rewrite;
    if (!is_object($term)) {
        if (is_int($term)) {
            $term = get_term($term, $taxonomy);
        } else {
            $term = get_term_by('slug', $term, $taxonomy);
        }
    }
    if (!is_object($term)) {
        $term = new WP_Error('invalid_term', __('Empty Term.'));
    }
    if (is_wp_error($term)) {
        return $term;
    }
    $taxonomy = $term->taxonomy;
    $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    /**
     * Filters the permalink structure for a terms before token replacement occurs.
     *
     * @since 4.9.0
     *
     * @param string  $termlink The permalink structure for the term's taxonomy.
     * @param WP_Term $term     The term object.
     */
    $termlink = apply_filters('pre_term_link', $termlink, $term);
    $slug = $term->slug;
    $t = get_taxonomy($taxonomy);
    if (empty($termlink)) {
        if ('category' === $taxonomy) {
            $termlink = '?cat=' . $term->term_id;
        } elseif ($t->query_var) {
            $termlink = "?{$t->query_var}={$slug}";
        } else {
            $termlink = "?taxonomy={$taxonomy}&term={$slug}";
        }
        $termlink = home_url($termlink);
    } else {
        if ($t->rewrite['hierarchical']) {
            $hierarchical_slugs = array();
            $ancestors = get_ancestors($term->term_id, $taxonomy, 'taxonomy');
            foreach ((array) $ancestors as $ancestor) {
                $ancestor_term = get_term($ancestor, $taxonomy);
                $hierarchical_slugs[] = $ancestor_term->slug;
            }
            $hierarchical_slugs = array_reverse($hierarchical_slugs);
            $hierarchical_slugs[] = $slug;
            $termlink = str_replace("%{$taxonomy}%", implode('/', $hierarchical_slugs), $termlink);
        } else {
            $termlink = str_replace("%{$taxonomy}%", $slug, $termlink);
        }
        $termlink = home_url(user_trailingslashit($termlink, 'category'));
    }
    // Back Compat filters.
    if ('post_tag' === $taxonomy) {
        /**
         * Filters the tag link.
         *
         * @since 2.3.0
         * @deprecated 2.5.0 Use 'term_link' instead.
         *
         * @param string $termlink Tag link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('tag_link', $termlink, $term->term_id);
    } elseif ('category' === $taxonomy) {
        /**
         * Filters the category link.
         *
         * @since 1.5.0
         * @deprecated 2.5.0 Use 'term_link' instead.
         *
         * @param string $termlink Category link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('category_link', $termlink, $term->term_id);
    }
    /**
     * Filters the term link.
     *
     * @since 2.5.0
     *
     * @param string $termlink Term link URL.
     * @param object $term     Term object.
     * @param string $taxonomy Taxonomy slug.
     */
    return apply_filters('term_link', $termlink, $term, $taxonomy);
}

WordPress Version: 4.9

/**
 * Generate a permalink for a taxonomy term archive.
 *
 * @since 2.5.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param object|int|string $term     The term object, ID, or slug whose link will be retrieved.
 * @param string            $taxonomy Optional. Taxonomy. Default empty.
 * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist.
 */
function get_term_link($term, $taxonomy = '')
{
    global $wp_rewrite;
    if (!is_object($term)) {
        if (is_int($term)) {
            $term = get_term($term, $taxonomy);
        } else {
            $term = get_term_by('slug', $term, $taxonomy);
        }
    }
    if (!is_object($term)) {
        $term = new WP_Error('invalid_term', __('Empty Term.'));
    }
    if (is_wp_error($term)) {
        return $term;
    }
    $taxonomy = $term->taxonomy;
    $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    /**
     * Filters the permalink structure for a terms before token replacement occurs.
     *
     * @since 4.9.0
     *
     * @param string  $termlink The permalink structure for the term's taxonomy.
     * @param WP_Term $term     The term object.
     */
    $termlink = apply_filters('pre_term_link', $termlink, $term);
    $slug = $term->slug;
    $t = get_taxonomy($taxonomy);
    if (empty($termlink)) {
        if ('category' == $taxonomy) {
            $termlink = '?cat=' . $term->term_id;
        } elseif ($t->query_var) {
            $termlink = "?{$t->query_var}={$slug}";
        } else {
            $termlink = "?taxonomy={$taxonomy}&term={$slug}";
        }
        $termlink = home_url($termlink);
    } else {
        if ($t->rewrite['hierarchical']) {
            $hierarchical_slugs = array();
            $ancestors = get_ancestors($term->term_id, $taxonomy, 'taxonomy');
            foreach ((array) $ancestors as $ancestor) {
                $ancestor_term = get_term($ancestor, $taxonomy);
                $hierarchical_slugs[] = $ancestor_term->slug;
            }
            $hierarchical_slugs = array_reverse($hierarchical_slugs);
            $hierarchical_slugs[] = $slug;
            $termlink = str_replace("%{$taxonomy}%", implode('/', $hierarchical_slugs), $termlink);
        } else {
            $termlink = str_replace("%{$taxonomy}%", $slug, $termlink);
        }
        $termlink = home_url(user_trailingslashit($termlink, 'category'));
    }
    // Back Compat filters.
    if ('post_tag' == $taxonomy) {
        /**
         * Filters the tag link.
         *
         * @since 2.3.0
         * @deprecated 2.5.0 Use 'term_link' instead.
         *
         * @param string $termlink Tag link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('tag_link', $termlink, $term->term_id);
    } elseif ('category' == $taxonomy) {
        /**
         * Filters the category link.
         *
         * @since 1.5.0
         * @deprecated 2.5.0 Use 'term_link' instead.
         *
         * @param string $termlink Category link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('category_link', $termlink, $term->term_id);
    }
    /**
     * Filters the term link.
     *
     * @since 2.5.0
     *
     * @param string $termlink Term link URL.
     * @param object $term     Term object.
     * @param string $taxonomy Taxonomy slug.
     */
    return apply_filters('term_link', $termlink, $term, $taxonomy);
}

WordPress Version: 4.6

/**
 * Generate a permalink for a taxonomy term archive.
 *
 * @since 2.5.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param object|int|string $term     The term object, ID, or slug whose link will be retrieved.
 * @param string            $taxonomy Optional. Taxonomy. Default empty.
 * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist.
 */
function get_term_link($term, $taxonomy = '')
{
    global $wp_rewrite;
    if (!is_object($term)) {
        if (is_int($term)) {
            $term = get_term($term, $taxonomy);
        } else {
            $term = get_term_by('slug', $term, $taxonomy);
        }
    }
    if (!is_object($term)) {
        $term = new WP_Error('invalid_term', __('Empty Term'));
    }
    if (is_wp_error($term)) {
        return $term;
    }
    $taxonomy = $term->taxonomy;
    $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    $slug = $term->slug;
    $t = get_taxonomy($taxonomy);
    if (empty($termlink)) {
        if ('category' == $taxonomy) {
            $termlink = '?cat=' . $term->term_id;
        } elseif ($t->query_var) {
            $termlink = "?{$t->query_var}={$slug}";
        } else {
            $termlink = "?taxonomy={$taxonomy}&term={$slug}";
        }
        $termlink = home_url($termlink);
    } else {
        if ($t->rewrite['hierarchical']) {
            $hierarchical_slugs = array();
            $ancestors = get_ancestors($term->term_id, $taxonomy, 'taxonomy');
            foreach ((array) $ancestors as $ancestor) {
                $ancestor_term = get_term($ancestor, $taxonomy);
                $hierarchical_slugs[] = $ancestor_term->slug;
            }
            $hierarchical_slugs = array_reverse($hierarchical_slugs);
            $hierarchical_slugs[] = $slug;
            $termlink = str_replace("%{$taxonomy}%", implode('/', $hierarchical_slugs), $termlink);
        } else {
            $termlink = str_replace("%{$taxonomy}%", $slug, $termlink);
        }
        $termlink = home_url(user_trailingslashit($termlink, 'category'));
    }
    // Back Compat filters.
    if ('post_tag' == $taxonomy) {
        /**
         * Filters the tag link.
         *
         * @since 2.3.0
         * @deprecated 2.5.0 Use 'term_link' instead.
         *
         * @param string $termlink Tag link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('tag_link', $termlink, $term->term_id);
    } elseif ('category' == $taxonomy) {
        /**
         * Filters the category link.
         *
         * @since 1.5.0
         * @deprecated 2.5.0 Use 'term_link' instead.
         *
         * @param string $termlink Category link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('category_link', $termlink, $term->term_id);
    }
    /**
     * Filters the term link.
     *
     * @since 2.5.0
     *
     * @param string $termlink Term link URL.
     * @param object $term     Term object.
     * @param string $taxonomy Taxonomy slug.
     */
    return apply_filters('term_link', $termlink, $term, $taxonomy);
}

WordPress Version: 4.3

/**
 * Generate a permalink for a taxonomy term archive.
 *
 * @since 2.5.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param object|int|string $term     The term object, ID, or slug whose link will be retrieved.
 * @param string            $taxonomy Optional. Taxonomy. Default empty.
 * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist.
 */
function get_term_link($term, $taxonomy = '')
{
    global $wp_rewrite;
    if (!is_object($term)) {
        if (is_int($term)) {
            $term = get_term($term, $taxonomy);
        } else {
            $term = get_term_by('slug', $term, $taxonomy);
        }
    }
    if (!is_object($term)) {
        $term = new WP_Error('invalid_term', __('Empty Term'));
    }
    if (is_wp_error($term)) {
        return $term;
    }
    $taxonomy = $term->taxonomy;
    $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    $slug = $term->slug;
    $t = get_taxonomy($taxonomy);
    if (empty($termlink)) {
        if ('category' == $taxonomy) {
            $termlink = '?cat=' . $term->term_id;
        } elseif ($t->query_var) {
            $termlink = "?{$t->query_var}={$slug}";
        } else {
            $termlink = "?taxonomy={$taxonomy}&term={$slug}";
        }
        $termlink = home_url($termlink);
    } else {
        if ($t->rewrite['hierarchical']) {
            $hierarchical_slugs = array();
            $ancestors = get_ancestors($term->term_id, $taxonomy, 'taxonomy');
            foreach ((array) $ancestors as $ancestor) {
                $ancestor_term = get_term($ancestor, $taxonomy);
                $hierarchical_slugs[] = $ancestor_term->slug;
            }
            $hierarchical_slugs = array_reverse($hierarchical_slugs);
            $hierarchical_slugs[] = $slug;
            $termlink = str_replace("%{$taxonomy}%", implode('/', $hierarchical_slugs), $termlink);
        } else {
            $termlink = str_replace("%{$taxonomy}%", $slug, $termlink);
        }
        $termlink = home_url(user_trailingslashit($termlink, 'category'));
    }
    // Back Compat filters.
    if ('post_tag' == $taxonomy) {
        /**
         * Filter the tag link.
         *
         * @since 2.3.0
         * @deprecated 2.5.0 Use 'term_link' instead.
         *
         * @param string $termlink Tag link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('tag_link', $termlink, $term->term_id);
    } elseif ('category' == $taxonomy) {
        /**
         * Filter the category link.
         *
         * @since 1.5.0
         * @deprecated 2.5.0 Use 'term_link' instead.
         *
         * @param string $termlink Category link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('category_link', $termlink, $term->term_id);
    }
    /**
     * Filter the term link.
     *
     * @since 2.5.0
     *
     * @param string $termlink Term link URL.
     * @param object $term     Term object.
     * @param string $taxonomy Taxonomy slug.
     */
    return apply_filters('term_link', $termlink, $term, $taxonomy);
}

WordPress Version: 4.1

/**
 * Generate a permalink for a taxonomy term archive.
 *
 * @since 2.5.0
 *
 * @param object|int|string $term     The term object, ID, or slug whose link will be retrieved.
 * @param string            $taxonomy Optional. Taxonomy. Default empty.
 * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist.
 */
function get_term_link($term, $taxonomy = '')
{
    global $wp_rewrite;
    if (!is_object($term)) {
        if (is_int($term)) {
            $term = get_term($term, $taxonomy);
        } else {
            $term = get_term_by('slug', $term, $taxonomy);
        }
    }
    if (!is_object($term)) {
        $term = new WP_Error('invalid_term', __('Empty Term'));
    }
    if (is_wp_error($term)) {
        return $term;
    }
    $taxonomy = $term->taxonomy;
    $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    $slug = $term->slug;
    $t = get_taxonomy($taxonomy);
    if (empty($termlink)) {
        if ('category' == $taxonomy) {
            $termlink = '?cat=' . $term->term_id;
        } elseif ($t->query_var) {
            $termlink = "?{$t->query_var}={$slug}";
        } else {
            $termlink = "?taxonomy={$taxonomy}&term={$slug}";
        }
        $termlink = home_url($termlink);
    } else {
        if ($t->rewrite['hierarchical']) {
            $hierarchical_slugs = array();
            $ancestors = get_ancestors($term->term_id, $taxonomy, 'taxonomy');
            foreach ((array) $ancestors as $ancestor) {
                $ancestor_term = get_term($ancestor, $taxonomy);
                $hierarchical_slugs[] = $ancestor_term->slug;
            }
            $hierarchical_slugs = array_reverse($hierarchical_slugs);
            $hierarchical_slugs[] = $slug;
            $termlink = str_replace("%{$taxonomy}%", implode('/', $hierarchical_slugs), $termlink);
        } else {
            $termlink = str_replace("%{$taxonomy}%", $slug, $termlink);
        }
        $termlink = home_url(user_trailingslashit($termlink, 'category'));
    }
    // Back Compat filters.
    if ('post_tag' == $taxonomy) {
        /**
         * Filter the tag link.
         *
         * @since 2.3.0
         * @deprecated 2.5.0 Use 'term_link' instead.
         *
         * @param string $termlink Tag link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('tag_link', $termlink, $term->term_id);
    } elseif ('category' == $taxonomy) {
        /**
         * Filter the category link.
         *
         * @since 1.5.0
         * @deprecated 2.5.0 Use 'term_link' instead.
         *
         * @param string $termlink Category link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('category_link', $termlink, $term->term_id);
    }
    /**
     * Filter the term link.
     *
     * @since 2.5.0
     *
     * @param string $termlink Term link URL.
     * @param object $term     Term object.
     * @param string $taxonomy Taxonomy slug.
     */
    return apply_filters('term_link', $termlink, $term, $taxonomy);
}

WordPress Version: 3.9

/**
 * Generates a permalink for a taxonomy term archive.
 *
 * @since 2.5.0
 *
 * @param object|int|string $term
 * @param string $taxonomy (optional if $term is object)
 * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist.
 */
function get_term_link($term, $taxonomy = '')
{
    global $wp_rewrite;
    if (!is_object($term)) {
        if (is_int($term)) {
            $term = get_term($term, $taxonomy);
        } else {
            $term = get_term_by('slug', $term, $taxonomy);
        }
    }
    if (!is_object($term)) {
        $term = new WP_Error('invalid_term', __('Empty Term'));
    }
    if (is_wp_error($term)) {
        return $term;
    }
    $taxonomy = $term->taxonomy;
    $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    $slug = $term->slug;
    $t = get_taxonomy($taxonomy);
    if (empty($termlink)) {
        if ('category' == $taxonomy) {
            $termlink = '?cat=' . $term->term_id;
        } elseif ($t->query_var) {
            $termlink = "?{$t->query_var}={$slug}";
        } else {
            $termlink = "?taxonomy={$taxonomy}&term={$slug}";
        }
        $termlink = home_url($termlink);
    } else {
        if ($t->rewrite['hierarchical']) {
            $hierarchical_slugs = array();
            $ancestors = get_ancestors($term->term_id, $taxonomy);
            foreach ((array) $ancestors as $ancestor) {
                $ancestor_term = get_term($ancestor, $taxonomy);
                $hierarchical_slugs[] = $ancestor_term->slug;
            }
            $hierarchical_slugs = array_reverse($hierarchical_slugs);
            $hierarchical_slugs[] = $slug;
            $termlink = str_replace("%{$taxonomy}%", implode('/', $hierarchical_slugs), $termlink);
        } else {
            $termlink = str_replace("%{$taxonomy}%", $slug, $termlink);
        }
        $termlink = home_url(user_trailingslashit($termlink, 'category'));
    }
    // Back Compat filters.
    if ('post_tag' == $taxonomy) {
        /**
         * Filter the tag link.
         *
         * @since 2.3.0
         * @deprecated 2.5.0 Use 'term_link' instead.
         *
         * @param string $termlink Tag link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('tag_link', $termlink, $term->term_id);
    } elseif ('category' == $taxonomy) {
        /**
         * Filter the category link.
         *
         * @since 1.5.0
         * @deprecated 2.5.0 Use 'term_link' instead.
         *
         * @param string $termlink Category link URL.
         * @param int    $term_id  Term ID.
         */
        $termlink = apply_filters('category_link', $termlink, $term->term_id);
    }
    /**
     * Filter the term link.
     *
     * @since 2.5.0
     *
     * @param string $termlink Term link URL.
     * @param object $term     Term object.
     * @param string $taxonomy Taxonomy slug.
     */
    return apply_filters('term_link', $termlink, $term, $taxonomy);
}

WordPress Version: 3.7

/**
 * Generates a permalink for a taxonomy term archive.
 *
 * @since 2.5.0
 *
 * @uses apply_filters() Calls 'term_link' with term link and term object, and taxonomy parameters.
 * @uses apply_filters() For the post_tag Taxonomy, Calls 'tag_link' with tag link and tag ID as parameters.
 * @uses apply_filters() For the category Taxonomy, Calls 'category_link' filter on category link and category ID.
 *
 * @param object|int|string $term
 * @param string $taxonomy (optional if $term is object)
 * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist.
 */
function get_term_link($term, $taxonomy = '')
{
    global $wp_rewrite;
    if (!is_object($term)) {
        if (is_int($term)) {
            $term = get_term($term, $taxonomy);
        } else {
            $term = get_term_by('slug', $term, $taxonomy);
        }
    }
    if (!is_object($term)) {
        $term = new WP_Error('invalid_term', __('Empty Term'));
    }
    if (is_wp_error($term)) {
        return $term;
    }
    $taxonomy = $term->taxonomy;
    $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    $slug = $term->slug;
    $t = get_taxonomy($taxonomy);
    if (empty($termlink)) {
        if ('category' == $taxonomy) {
            $termlink = '?cat=' . $term->term_id;
        } elseif ($t->query_var) {
            $termlink = "?{$t->query_var}={$slug}";
        } else {
            $termlink = "?taxonomy={$taxonomy}&term={$slug}";
        }
        $termlink = home_url($termlink);
    } else {
        if ($t->rewrite['hierarchical']) {
            $hierarchical_slugs = array();
            $ancestors = get_ancestors($term->term_id, $taxonomy);
            foreach ((array) $ancestors as $ancestor) {
                $ancestor_term = get_term($ancestor, $taxonomy);
                $hierarchical_slugs[] = $ancestor_term->slug;
            }
            $hierarchical_slugs = array_reverse($hierarchical_slugs);
            $hierarchical_slugs[] = $slug;
            $termlink = str_replace("%{$taxonomy}%", implode('/', $hierarchical_slugs), $termlink);
        } else {
            $termlink = str_replace("%{$taxonomy}%", $slug, $termlink);
        }
        $termlink = home_url(user_trailingslashit($termlink, 'category'));
    }
    // Back Compat filters.
    if ('post_tag' == $taxonomy) {
        $termlink = apply_filters('tag_link', $termlink, $term->term_id);
    } elseif ('category' == $taxonomy) {
        $termlink = apply_filters('category_link', $termlink, $term->term_id);
    }
    return apply_filters('term_link', $termlink, $term, $taxonomy);
}