Created
January 24, 2016 18:06
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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