Display wordpress custom taxonomy with separators and title attribute

I was looking and having trouble finding a function that would not only return my custom taxonomy terms, but with the title description attribute so that when people hover over the link they get some more info.

Get_the_terms_list function did half of what I wanted – I got the custom taxonomy plus a separator if more than one, but no description:

			<?php echo get_the_term_list( $post->ID, 'film-year', '', ', ', '' ); ?>

So here is my solution:

			$terms = get_the_terms( $post->ID, 'film-year' );

			if ( $terms && ! is_wp_error( $terms ) ) : 

				$year_links = array();

				foreach ( $terms as $term ) {
				    $term_name = $term->name; // get the ID of the term
							$year_links[] = '<a href="'.get_term_link($term).'" title="View all films from '.$term_name.'">'.$term_name.'</a>';

				$filmyearlinks = join( ", ", $year_links );

				Film year: <span><?php echo $filmyearlinks; ?></span>

			<?php endif; ?>


About Steven Chu

Hi, I'm Steven! I'm an entrepreneur, photographer and art director in New York. Follow this blog for self expression, fun, and most importantly: looking comfortable, at ease, and amazing in your photos no matter who takes them! I dedicate this to my amazing friends who have let me inadvertently turn all of our hangouts and travel photos into a never ending photoshoot of fun. The proof is in the pudding-- our photos rock. My other projects: I'm the founder of InstaTechie.com, a face-to-face tech concierge service for NYC. Book a techie to walk you through something you want to learn! My work focuses on socially engaged art projects which use technology to create access to resources for communities. Visit Steven Chu Studio (stevenchustudio.com) for branding & design work or Steven Chu (stevenchu.com) for photography projects.

Leave a Reply