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 code in my home.php, the very first post class does not get the class while the others do. Same thing when i move this code to functions.php. I get php errors when i remove the hook around it and just add the filter.

add_action('pre_get_posts', 'theme_add_post_class');

function theme_add_post_class() {

    /** Add custom post class */
    add_filter( 'post_class', function( $classes ) {
        $classes[] = 'span4';
        return $classes;
    } );


share|improve this question
up vote 1 down vote accepted
function wpse80148_filter_post_class( $classes ) {
    if( is_home() || is_front_page() )
        $classes[] = 'span4';
    return $classes;
add_filter( 'post_class', 'wpse80148_filter_post_class' );
share|improve this answer
Please explain why that could solve the problem. – toscho Jan 11 '13 at 12:37
imho, it is more down to the location of the code; diggy's suggestion should work if added into functions.php – Michael Jan 11 '13 at 13:00
that's right, its working, but only in functions.php. thanks – James Mitch Jan 11 '13 at 13:46

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.