0

I have a custom taxonomy called services. Each service term will have a description. I am using get_the_term_list to show all the terms attached to each post. When hovering over the term link in the front-end I would like to show the term description just like WordPress does within the back-end when you hover over any link.

1 Answer 1

0

If you mean to add the description of the term as a title attribute which will show on hover then you can "fork" get_the_term_list function to a version that would add the title attribute, something like this should work:

function get_terms_with_desc( $id = 0 , $taxonomy = 'post_tag', $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" title="'.esc_attr( $term->description ).'">' . $term->name . '</a>';
    }
    $term_links = apply_filters( "term_links-$taxonomy", $term_links );
    return $before . join( $sep, $term_links ) . $after;
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.