Skip to content

Instantly share code, notes, and snippets.

Created January 24, 2016 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/17260b543e9854d7c894 to your computer and use it in GitHub Desktop.
Save anonymous/17260b543e9854d7c894 to your computer and use it in GitHub Desktop.
Add class to first post in WordPress loop. A snippet for the functions.php.
add_filter( 'post_class', 'add_class_first_post' );
function add_class_first_post( $classes ) {
if ( ! is_admin() ) { // add any conditional here (ex. homepage only), this might not be needed
global $wp_query;
if( 0 == $wp_query->current_post )
$classes[] = 'first'; // class name
return $classes;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment