{"id":150,"date":"2018-07-23T23:09:47","date_gmt":"2018-07-23T21:09:47","guid":{"rendered":"https:\/\/mzhg.space\/?p=150"},"modified":"2018-07-23T23:17:12","modified_gmt":"2018-07-23T21:17:12","slug":"adding-a-custom-css-class-to-posts-sticked-by-category-sticky-post-plugin","status":"publish","type":"post","link":"https:\/\/mzhg.space\/?p=150","title":{"rendered":"Adding a Custom Css Class to Posts Sticked by &#8220;Category Sticky Post&#8221; Plugin"},"content":{"rendered":"<p>While working on this blog, I needed to set posts as sticky for a specific category. to do that I use the plugin <a href=\"https:\/\/wordpress.org\/plugins\/category-sticky-post\/\" target=\"_blank\" rel=\"noopener\">Category Sticky Post<\/a> which work perfectly for me.<\/p>\n<p>However, my theme use the css class &#8220;sticky&#8221; for sticky posts but the plugin don&#8217;t add it, so I needed to add a small fix into the functions.php file of my child theme.<\/p>\n<p>&nbsp;<\/p>\n<p>It&#8217;s a simple filter hook on &#8220;post_class&#8221;, here&#8217;s the code:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\r\nfunction add_sticky_to_category_sticky($classes) {\r\nif (in_array('category-sticky', $classes))\r\n{\r\n$classes&#x5B;] = 'sticky';\r\n}\r\nreturn $classes;\r\n}\r\nadd_filter( 'post_class', 'add_sticky_to_category_sticky', 11, 1 );\r\n\r\n<\/pre>\n<p>I look for the plugin specific css class and if found, I simply add mine.<\/p>\n<p>&nbsp;<\/p>\n<p><del>The only unknown here is if my hook will always be called after the plugin or not \ud83d\ude09<\/del><\/p>\n<p>Edit: after a fast google search, I added priority to the hook, the plugin use the default value of ten, so I used 11.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While working on this blog, I needed to set posts as sticky for a specific category. to do that I use the plugin Category Sticky Post which work perfectly for me. However, my theme use the css class &#8220;sticky&#8221; for sticky posts but the plugin don&#8217;t add it, so I needed to add a small&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,5],"tags":[24,23,26,22,25],"class_list":["post-150","post","type-post","status-publish","format-standard","hentry","category-php","category-programming","tag-css","tag-php","tag-plugin","tag-programming","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/mzhg.space\/index.php?rest_route=\/wp\/v2\/posts\/150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mzhg.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mzhg.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mzhg.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mzhg.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=150"}],"version-history":[{"count":6,"href":"https:\/\/mzhg.space\/index.php?rest_route=\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":156,"href":"https:\/\/mzhg.space\/index.php?rest_route=\/wp\/v2\/posts\/150\/revisions\/156"}],"wp:attachment":[{"href":"https:\/\/mzhg.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mzhg.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mzhg.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}