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

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

Want to add post tag name to body class - I am successful in using the code below to add category to body class -

 //adds new body class for post category
add_filter('body_class', 'add_category_class_single');
function add_category_class_single($classes){
     global $post;

    $category = get_the_category($post->ID);
    $slug = $category[0]->slug;
    $classes[] = 'post-category-' . $slug;

    return $classes;

however when i try to use get_the_tags i am not having any luck - any ideas?

share|improve this question

That is because the get_the_tags() function returns an array with the tag id as the key value. You could use array_values( get_the_tags( $post->ID ) ). That should do the trick.

share|improve this answer
well done +1 .. – kaiser Dec 16 '11 at 18:17
joshua - you nailed it - THANKS!!! – aj martin Dec 16 '11 at 20:57

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.