This must be pretty simple, but it is eluding me. I need to add several classes to post_class() http://codex.wordpress.org/Function_Reference/post_class

I can add one class in a page template, as below:


but I need to add several more, i.e. $current_post and $current_in_total

They won't echo, and they won't output this way: post_class($current_post; $even_odd; $current_in_total;)

I need to output these in a page template using post_class(), not add them via a hook in functions.php



Multiple post classes should be separated by a single space or should be in an array.

post_class("$even_odd $current_post $current_in_total");


post_class(array($even_odd, $current_post, $current_in_total));

  • Ah, I was using single quotes. The first example works fine. Thanks! – markratledge Nov 5 '12 at 0:19
  • 1
    Variables don't 'expand' inside single quotes – s_ha_dum Nov 5 '12 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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