Filter the post css classes added on HTML markup.
Parameters
- $post_id
string Post ID.
- array()
array CSS classes added on post HTML markup.
Changelog
- Introduced in Jetpack 3.8.0
How to use this hook
Notes
You could use this filter to add each post’s category slugs to the container’s class, like so:
function add_css_classes_on_related_posts( $classes, $post_id ) {
$categories = get_the_category( $post_id );
foreach ( $categories as $category ) {
$classes[] = 'category-' . $category->slug;
}
return $classes;
}
add_filter('jetpack_relatedposts_filter_post_css_classes', 'add_css_classes_on_related_posts', 10, 2);
That can be helpful when one wants to style Related Posts differently depending on the post’s category, for example.