WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
up vote 3 down vote accepted

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 by the_terms():

add_filter('term_links-cities', 'ad_filter_links');

function ad_filter_links($term_links) {
    foreach ($term_links as $term_link) {
        $term_link = str_replace('<a ', '<a class="fancybox"', $term_link);
    return $term_links;
share|improve this answer
whoah! that's what i'm looking for. Thanks you very much! By the way, how did you search this hook? I spent hours on google with no success in finding a similar suggestion – Susan Siqueira Feb 14 '13 at 18:54
@SusanSiqueira you are welcome. I rely on the source code to find hooks, this one from get_the_term_list() function used by the_terms() which both are located in wp-includes/category-template.php. – Ahmad M Feb 14 '13 at 19:03
aaaa I looked up the code and found the hook. now I'm beginning to understand how filter works. thanks again! – Susan Siqueira Feb 14 '13 at 23:25

Your Answer


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.