Archived topic
CSS class to identify sticky posts?
1 reply · Started by Zarar on October 4, 2022
In my Query Loop I'm retrieving a set of posts. One of those posts is stickied and correctly shows up as the first post in the list. However, when it's being rendered I have no way of knowing which one is a sticky post. I would have hoped that there would be a CSS class which would also mark the post so I could apply some custom styling.
Any thoughts on how I might style a sticky post retrieved using Query Loop?
Hi Zarar,
You can try this PHP snippet to add stikcy-post class to the sticky posts.
add_filter( 'post_class', 'sticky_post_class', 10, 2);
function sticky_post_class( $classes, $class) {
if (is_sticky()) {
$classes[] = 'sticky-post';
return $classes;
}
return $classes;
}