Use get_the_terms()
and create a custom array:
function wpse_31396_terms_with_desc( $post_id = NULL, $taxonomy = 'post_tag' )
{
NULL === $post_id && $post_id = get_the_ID();
if ( empty ( $post_id ) )
{
return '';
}
$terms = get_the_terms( $post_id, $taxonomy );
if ( empty ( $terms ) )
{
return '';
}
$list = array ();
foreach ( $terms as $term )
{
$list[ $term->term_id ] = array(
'url' => get_term_link( $term, $taxonomy ),
'name' => $term->name,
'description' => $term->description
);
}
return $list;
}
Sample usage for the functions.php
:
add_filter( 'the_content', 'wpse_31396_add_terms_with_desc' );
function wpse_31396_add_terms_with_desc( $content )
{
$tags = wpse_31396_terms_with_desc();
if ( '' === $tags )
{
return $content;
}
$taglist="<h2>Cross Reference</h2><ul class="taglist-with-desc">";
foreach ( $tags as $tag )
{
$desc = empty ( $tag['description'] )
? '' : '<div class="tagdesc">' . wpautop( $tag['description'] ) . '</div>';
$taglist .= sprintf(
'<li><a href="https://wordpress.stackexchange.com/questions/31396/%1$s">%2$s</a>%3$s</li>',
$tag['url'],
$tag['name'],
$desc
);
}
return $content . $taglist . '</ul>';
}