Skip to content

Instantly share code, notes, and snippets.

Last active Jan 3, 2019
What would you like to do?
* Display Posts Shortcode, add category classes
* @see
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' );

This comment has been minimized.

Copy link

@critterles critterles commented Dec 4, 2017

Thanks for the quick response. While I coded many years ago, I'm still working on CSS. Can the above code be added to the Custom CSS area at the bottom of the CSStyle file? or maybe using the WordPress Customization option for CSS? In your example is "catagory" and "Cat" variables for the category I want to affect? Also where would I set the font size and color in your statement?

I found this code but it doesn't seem to work.
.category-news {
font-size: 18px;
font-style: italic;
Thanks Again


This comment has been minimized.

Copy link

@FredCohn FredCohn commented Jan 22, 2018

there is a typo in the code snippet @ line 11: "$categoriess" should be "$categories"


This comment has been minimized.

Copy link
Owner Author

@billerickson billerickson commented Jan 3, 2019

This code snippet goes in a core functionality plugin or Code Snippets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment