apply_filters ( 'jetpack_relatedposts_filter_post_css_classes', array array(), string $post_id )

Filter the post css classes added on HTML markup.

Source file: modules/related-posts/jetpack-related-posts.php

View in GitHub

Parameters

array()

(array) array() CSS classes added on post HTML markup.

$post_id

(string) Post ID.


Changelog

Since: Jetpack 3.8.0


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.

Have a note to contribute?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s