Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to add a class to a container within a query, ideally I'd like to use the terms from a custom taxonomy I have setup (guide-categories).

As an example:

<div class="myclass *taxonomy term*">

Any help would be much appreciated, been looking around trying to find out how to do this for a while, but haven't had any luck yet!

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You could do something like this

<?php $terms = get_the_terms( $post->ID, 'taxonomy_name' ); ?>
<div class="myclass<?php foreach( $terms as $term ) echo ' ' . $term->slug; ?>">
    <!-- content -->

share|improve this answer
Thanks! this works but would it be possible to show the term slug rather than name? (otherwise I get caps and spaces in some terms) –  user862153 Jan 22 '12 at 0:01
Yeah definitely, you could use $term->slug instead of $term->name. –  Jared Jan 22 '12 at 0:13
excellent, thanks for the help :) –  user862153 Jan 22 '12 at 0:21

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.