DPS – Add class to current post

Using Display Posts Shortcode, if the current post is included in a listing, this snippet adds a class of “current” to it.

 * Display Posts Shortcode - "current" class on current post 
function be_dps_current_class( $classes ) {
  if( get_the_ID() == get_queried_object_id() )
    $classes[] = 'current';
  return $classes;
add_filter( 'display_posts_shortcode_post_class', 'be_dps_current_class' );

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk