DPS, Add Category Classes

/**
 * Display Posts Shortcode, add category classes 
 * @link https://displayposts.com/2019/01/03/add-category-classes/
 */
function be_dps_add_category_classes( $classes ) {
  $categories = get_the_terms( get_the_ID(), 'category' );
  if( ! empty( $categories ) && ! is_wp_error( $categories ) ) {
    foreach( $categories as $category ) {
      $classes[] = 'cat-' . $category->slug;
    }
  }
  return $classes;
}
add_filter( 'display_posts_shortcode_post_class', 'be_dps_add_category_classes' );

For more information, see this support ticket

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