-
-
Save billerickson/ad862c6b0c9f235f999b6645a289fe82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 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' ); |
there is a typo in the code snippet @ line 11: "$categoriess" should be "$categories"
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
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