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;
    } );


function wpse80148_filter_post_class( $classes ) {
    if( is_home() || is_front_page() )
        $classes[] = 'span4';
    return $classes;
add_filter( 'post_class', 'wpse80148_filter_post_class' );
|improve this answer|||||
  • 1
    Please explain why that could solve the problem. – fuxia 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 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.