Skip to content

Instantly share code, notes, and snippets.

@atanas-dev
Last active July 24, 2019 17:46
Show Gist options
  • Save atanas-dev/7de450a79dcdf51a0991cae98f5ab3c7 to your computer and use it in GitHub Desktop.
Save atanas-dev/7de450a79dcdf51a0991cae98f5ab3c7 to your computer and use it in GitHub Desktop.
<?php
// This code is UNTESTED!
function foo_add_class_to_first_three_posts_or_whatever( $post_class ) {
global $wp_query;
if ( $wp_query && $wp_query->current_post < 3 && is_main_query() && ! is_singular() && ! is_search() ) {
$post_class .= ' one-of-the-top-trio';
}
return $post_class;
}
add_filter( 'post_class', 'foo_add_class_to_first_three_posts_or_whatever' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment