I need to add a css class to every <a>
element retrieved by the_terms()
(or similar function) in order to open the taxonomy permalink in a fancybox modal window.
I’ve been searching this whole afternoon for a Filter that could handle it, with no success.
Anyway, I got into this (poor) solution below:
$cities = get_the_terms($post->ID, 'cities');
foreach ($cities as $city) {
echo '<a class="fancybox" href="'. get_term_link( $city->slug, 'cities' ).'">'.$city->name. '</a>' ;
}
But it’s too ‘ugly’ to put in a template file.
Is there any wordpress filter that deals with this question of permalink html generation?
Thanks a lot!
The filter you are looking for is
term_links-$taxonomy
, where$taxonomy
is the taxonomy name. This will filter the$term_links
links array before outputting bythe_terms()
: