Reply To: Changing the Styling for Latest Post via Child Theme

Home Forums Support Changing the Styling for Latest Post via Child Theme Reply To: Changing the Styling for Latest Post via Child Theme

#51302
Tom
Lead Developer
Lead Developer

Hi Michael,

How about adding a class to the first post in the loop using a function?

add_filter( 'post_class', 'generate_first_post_class' );
function generate_first_post_class( $classes ) {
    global $wp_query;
    if( 0 == $wp_query->current_post ) :
        $classes[] = 'first';
    endif;
	
	return $classes;
}

Then you can target that first post easily.

Let me know 🙂