Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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;
}
share|improve this answer
    
Perfect. Thank you for your help! –  Matt Mar 18 '13 at 14:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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