apply_filters( ‘term_link’, string $termlink, WP_Term $term, string $taxonomy )

Filters the term link.

Parameters

$termlinkstring
Term link URL.
$termWP_Term
Term object.
$taxonomystring
Taxonomy slug.

More Information

This filter is applied to the link URL for a term prior to printing by the function get_term_link() .

Source

return apply_filters( 'term_link', $termlink, $term, $taxonomy );

Changelog

VersionDescription
2.5.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    If you are using a solution to keep same slug for both custom post type and taxonomies, such like:

    /course/course-name
    /course/course-category-name

    You should follow those steps to make it working:

    1. Register taxonomy course_category with rewrite slug = ‘course-category’.
    2. Register post type course with rewrite slug ‘course’.
    2. Add filter to term_link:

    function wpdocs_change_course_category_link( $url, $term, $taxonomy ) {
    	if ( 'course_category' !== $taxonomy ) {
    		return $url;
    	}
    
    	return str_replace( '/course-category/', '/course/', $url );
    }
    add_filter( 'term_link', 'wpdocs_change_course_category_link', 10, 3 );

    Remember to flush permalink once to apply changes (on Settings / Permalinks).

You must log in before being able to contribute a note or feedback.