Title: get_term_link
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_term_link( WP_Term|int|string $term, string $taxonomy ): string|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#wp--skip-link--target)

Generates a permalink for a taxonomy term archive.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#parameters)󠁿

 `$term`[WP_Term](https://developer.wordpress.org/reference/classes/wp_term/)|int
|stringrequired

The term object, ID, or slug whose link will be retrieved.

`$taxonomy`stringoptional

Taxonomy. Default empty.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#return)󠁿

 string|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) 
URL of the taxonomy term archive on success, [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
if term does not exist.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#more-information)󠁿

 * Since the term can be an object, integer, or string, make sure that any numbers
   you pass in are explicitly converted to an integer (example: (int) $term_id).
   Otherwise the function will assume that $term is a slug instead of a term ID.
 * PHP may halt if you attempt to print an error result ("Catchable fatal error:
   Object of class [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
   could not be converted to string"). You should always use [ is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)
   to check the result of this function, in case the term does not exist.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#source)󠁿

    ```php
    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 '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 '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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/taxonomy.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/taxonomy.php#L4666)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/taxonomy.php#L4666-L4767)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#hooks)󠁿

 [apply_filters( ‘category_link’, string $termlink, int $term_id )](https://developer.wordpress.org/reference/hooks/category_link/)

Filters the category link.

 [apply_filters( ‘pre_term_link’, string $termlink, WP_Term $term )](https://developer.wordpress.org/reference/hooks/pre_term_link/)

Filters the permalink structure for a term before token replacement occurs.

 [apply_filters( ‘tag_link’, string $termlink, int $term_id )](https://developer.wordpress.org/reference/hooks/tag_link/)

Filters the tag link.

 [apply_filters( ‘term_link’, string $termlink, WP_Term $term, string $taxonomy )](https://developer.wordpress.org/reference/hooks/term_link/)

Filters the term link.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#related)󠁿

| Uses | Description | 
| [get_ancestors()](https://developer.wordpress.org/reference/functions/get_ancestors/)`wp-includes/taxonomy.php` |

Gets an array of ancestor IDs for a given object.

  | 
| [get_term_by()](https://developer.wordpress.org/reference/functions/get_term_by/)`wp-includes/taxonomy.php` |

Gets all term data from database by term field and data.

  | 
| [user_trailingslashit()](https://developer.wordpress.org/reference/functions/user_trailingslashit/)`wp-includes/link-template.php` |

Retrieves a trailing-slashed string if the site is set for adding trailing slashes.

  | 
| [WP_Rewrite::get_extra_permastruct()](https://developer.wordpress.org/reference/classes/wp_rewrite/get_extra_permastruct/)`wp-includes/class-wp-rewrite.php` |

Retrieves an extra permalink structure by name.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [get_term()](https://developer.wordpress.org/reference/functions/get_term/)`wp-includes/taxonomy.php` |

Gets all term data from database by term ID.

  | 
| [get_taxonomy()](https://developer.wordpress.org/reference/functions/get_taxonomy/)`wp-includes/taxonomy.php` |

Retrieves the taxonomy object of $taxonomy.

  | 
| [home_url()](https://developer.wordpress.org/reference/functions/home_url/)`wp-includes/link-template.php` |

Retrieves the URL for the current site where the front end is accessible.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 7 more](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#)

| Used by | Description | 
| [_block_bindings_term_data_get_value()](https://developer.wordpress.org/reference/functions/_block_bindings_term_data_get_value/)`wp-includes/block-bindings/term-data.php` |

Gets value for Term Data source.

  | 
| [WP_REST_Term_Search_Handler::prepare_item()](https://developer.wordpress.org/reference/classes/wp_rest_term_search_handler/prepare_item/)`wp-includes/rest-api/search/class-wp-rest-term-search-handler.php` |

Prepares the search result for a given term ID.

  | 
| [WP_Sitemaps_Taxonomies::get_url_list()](https://developer.wordpress.org/reference/classes/wp_sitemaps_taxonomies/get_url_list/)`wp-includes/sitemaps/providers/class-wp-sitemaps-taxonomies.php` |

Gets a URL list for a taxonomy sitemap.

  | 
| [get_term_parents_list()](https://developer.wordpress.org/reference/functions/get_term_parents_list/)`wp-includes/category-template.php` |

Retrieves term parents with separator.

  | 
| [WP_REST_Terms_Controller::prepare_item_for_response()](https://developer.wordpress.org/reference/classes/wp_rest_terms_controller/prepare_item_for_response/)`wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php` |

Prepares a single term output for response.

  | 
| [WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item()](https://developer.wordpress.org/reference/classes/wp_customize_nav_menu_item_setting/value_as_wp_post_nav_menu_item/)`wp-includes/customize/class-wp-customize-nav-menu-item-setting.php` |

Get the value emulated into a [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/) and set up as a nav_menu_item.

  | 
| [WP_Customize_Nav_Menus::search_available_items_query()](https://developer.wordpress.org/reference/classes/wp_customize_nav_menus/search_available_items_query/)`wp-includes/class-wp-customize-nav-menus.php` |

Performs post queries for available-item searching.

  | 
| [WP_Customize_Nav_Menus::load_available_items_query()](https://developer.wordpress.org/reference/classes/wp_customize_nav_menus/load_available_items_query/)`wp-includes/class-wp-customize-nav-menus.php` |

Performs the post_type and taxonomy queries for loading available menu items.

  | 
| [WP_Terms_List_Table::handle_row_actions()](https://developer.wordpress.org/reference/classes/wp_terms_list_table/handle_row_actions/)`wp-admin/includes/class-wp-terms-list-table.php` |

Generates and displays row action links.

  | 
| [Walker_Category::start_el()](https://developer.wordpress.org/reference/classes/walker_category/start_el/)`wp-includes/class-walker-category.php` |

Starts the element output.

  | 
| [get_the_term_list()](https://developer.wordpress.org/reference/functions/get_the_term_list/)`wp-includes/category-template.php` |

Retrieves a post’s terms as a list with specified format.

  | 
| [wp_tag_cloud()](https://developer.wordpress.org/reference/functions/wp_tag_cloud/)`wp-includes/category-template.php` |

Displays a tag cloud.

  | 
| [get_category_link()](https://developer.wordpress.org/reference/functions/get_category_link/)`wp-includes/category-template.php` |

Retrieves category link URL.

  | 
| [get_the_taxonomies()](https://developer.wordpress.org/reference/functions/get_the_taxonomies/)`wp-includes/taxonomy.php` |

Retrieves all taxonomies associated with a post.

  | 
| [get_term_feed_link()](https://developer.wordpress.org/reference/functions/get_term_feed_link/)`wp-includes/link-template.php` |

Retrieves the feed link for a term.

  | 
| [wp_admin_bar_edit_menu()](https://developer.wordpress.org/reference/functions/wp_admin_bar_edit_menu/)`wp-includes/admin-bar.php` |

Provides an edit link for posts and terms.

  | 
| [redirect_canonical()](https://developer.wordpress.org/reference/functions/redirect_canonical/)`wp-includes/canonical.php` |

Redirects incoming links to the proper URL based on the site url.

  | 
| [get_post_format_link()](https://developer.wordpress.org/reference/functions/get_post_format_link/)`wp-includes/post-formats.php` |

Returns a link to a post format index.

  | 
| [wp_setup_nav_menu_item()](https://developer.wordpress.org/reference/functions/wp_setup_nav_menu_item/)`wp-includes/nav-menu.php` |

Decorates a menu item object with the shared navigation menu item properties.

  |

[Show 14 more](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#comment-content-500)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_term_link/#comment-500)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F%23comment-500)
     Vote results for this note: 10[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F%23comment-500)
 4.      ```php
         $terms = get_terms( 'species' );
     
         echo '<ul>';
     
         foreach ( $terms as $term ) {
     
             // The $term is an object, so we don't need to specify the $taxonomy.
             $term_link = get_term_link( $term );
     
             // If there was an error, continue to the next term.
             if ( is_wp_error( $term_link ) ) {
                 continue;
             }
     
             // We successfully got a link. Print it out.
             echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>';
         }
     
         echo '</ul>';
         ```
     
 5.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F%3Freplytocom%3D500%23feedback-editor-500)
 6.   [Skip to note 6 content](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#comment-content-4103)
 7.    [Ravi Khadka](https://profiles.wordpress.org/ravikhadka/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_term_link/#comment-4103)
 8.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F%23comment-4103)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F%23comment-4103)
 9.  /* check term and error */
 10.     ```php
         $dr_terms = get_terms( 'your_term_name' );
         if ( ! is_wp_error( $dr_terms ) && ! empty( $dr_terms ) ) {
             echo '<ul class="your-class-name">';
             foreach ( $dr_terms as $dr_term ) {
                 echo '<li><a href="' . get_term_link( $dr_term->slug, 'your_term_name' ) . '">' . __( $term->name ) . '</a></li>';
             }
             echo '</ul>';
         }
         ```
     
 11.  * since $dr_term is an object, it is better to pass the whole thing via get_term_link(
        $dr_term ) instead passing the slug and the taxonomy like you did in your example.
      * [jnz31](https://profiles.wordpress.org/jnz31/) [4 years ago](https://developer.wordpress.org/reference/functions/get_term_link/#comment-5764)
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F%3Freplytocom%3D4103%23feedback-editor-4103)
 13.  [Skip to note 7 content](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#comment-content-6503)
 14.   [Pablo Pacheco](https://profiles.wordpress.org/karzin/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/get_term_link/#comment-6503)
 15. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F%23comment-6503)
     Vote results for this note: -1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F%23comment-6503)
 16. In order to avoid errors like `invalid_term` or `empty term`, if you pass the 
     first parameter as the **term id**, you should better make sure the first parameter
     is an integer, or you can simply convert it or type cast it. Example:
 17.     ```php
         get_term_link( (int) $term['term_id'], 'category' )
         ```
     
 18.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F%3Freplytocom%3D6503%23feedback-editor-6503)
 19.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/get_term_link/?output_format=md#comment-content-2796)
 20.   [Md. Jwel Miah](https://profiles.wordpress.org/mdjwel/)  [  8 years ago  ](https://developer.wordpress.org/reference/functions/get_term_link/#comment-2796)
 21. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F%23comment-2796)
     Vote results for this note: -3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F%23comment-2796)
 22.     ```php
         $terms = get_terms('species');
         if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
         	echo '<ul>';
         	foreach ($terms as $term) {
         		echo '<li><a href="'.get_term_link($term->slug, 'species').'">'.$term->name.'</a></li>';
         	}
         	echo '</ul>';
         }
         ```
     
 23.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F%3Freplytocom%3D2796%23feedback-editor-2796)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_term_link%2F)
before being able to contribute a note or feedback.