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 have this class for my posts:

<?php post_class( 'entry-image' ); ?>

I want to add the category names to get isotope work, i followed this guide http://www.acegoulet.com/2012/03/isotope-and-wordpress-how-i-did-it/ and i used this code to get category names:

$post_cats = get_the_category(); foreach( $post_cats as $category ) { echo $category->slug.' ';}

but this doesn't work. I tried to add a comma between the class and the category:

<?php post_class( 'entry-image', $post_cats = get_the_category(); foreach( $post_cats as $category ) { echo $category->slug.' ';} ); ?>

I checked the firebug but I don't see category name in loops (posts).
Why this doesn't work?

Thank you for help!

share|improve this question
up vote 1 down vote accepted

You have to pass the values, not echo them.

So something like this should work:

$post_cats = get_the_category();
$slugs = wp_list_pluck( $post_cats, 'slug' );
post_class( join( ' ', $slugs );
share|improve this answer
Thank you so much! – Fuiba Apr 15 '13 at 19:49

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.