[Support request] CSS class to identify sticky posts?

Home Forums Support [Support request] CSS class to identify sticky posts?

Home Forums Support CSS class to identify sticky posts?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2362638
    Zarar

    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?

    #2363141
    Ying
    Staff
    Customer Support

    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;
    }
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.