I search here and on Google and I can't find answer to my question, just hope you will find it relevant.

I'm doing a magazine website and I need to display names of contributors as a byline. I'm taking the information from the taxonomy 'Contributor' to display their names.

<?php echo get_the_term_list( $post->ID , 'contributors', 'By ',' and '); ?>

That gives me, By contributor1 and contributor2 and contributor3 and contributor4

But I would like to have something like that instead:

By contributor1, contributor2, contributor3 and contributor4

Maybe it's not possible, let me know.

Thanks in advance,



get_the_term_list uses get_the_terms to fetch the term objects. You can use that function instead and build the list however you'd like.

| improve this answer | |

If you look at the source...

1420             */
1421            $term_links = apply_filters( "term_links-$taxonomy", $links );
1423            return $before . join( $sep, $term_links ) . $after;
1424    }

... you will see that there is no filter that will allow you to alter the string in a way that effects where the separator occurs.

You could pipe the output through some regex but regex on markup is tricky and prone to error. You'd be better off copying that core function, renaming it, and altering it to do what you need.

| improve this answer | |

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