Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
1  
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
add comment

Your Answer

 
discard

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.