DPS, Add Category Classes

* Display Posts Shortcode, add category classes
* @see 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' );
view raw functions.php hosted with ❤ by GitHub

For more information, see: https://wordpress.org/support/topic/can-you-set-font-size-and-color-per-category/

Display Posts Shortcode

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

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

Let's Talk