#42363 closed enhancement (maybelater)
Add a filter into get_the_term_list function.
Reported by: | francescotaurino | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.8.2 |
Component: | Taxonomy | Keywords: | |
Focuses: | template | Cc: |
Description
This allows you to create a custom link and use the WP_Term object.
<?php /** * 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; } /** * Filters the term link for a given taxonomy. * * The dynamic portion of the filter name, `$taxonomy`, refers * to the taxonomy slug. * * @since 4.8.4 * * @param string HTML link. * @param object $term WP_Term object */ $links[] = apply_filters( "term_link-{$taxonomy}", '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>', $term ); }
Attachments (1)
Change History (3)
Note: See
TracTickets for help on using
tickets.
get_the_term_list function