{"id":117923,"date":"2013-07-02T11:30:03","date_gmt":"2013-07-02T15:30:03","guid":{"rendered":"http:\/\/wpmu.org\/?p=117923"},"modified":"2013-07-02T11:30:32","modified_gmt":"2013-07-02T15:30:32","slug":"how-to-exclude-category-from-wordpress-homepage","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/how-to-exclude-category-from-wordpress-homepage\/","title":{"rendered":"How to Exclude a Category from Your WordPress Homepage"},"content":{"rendered":"<p>For one reason or another, you may not want posts from one or more categories appearing in the stream of posts that show up on your homepage. This little bit of code will let you remove whichever categories you like from that stream.<\/p>\n<p>Place the following into your functions file. (Appearance &gt; Editor &gt; Theme Functions \u2013 functions.php)<\/p>\n<p>In this example, the numbers 3, 5, and 23 are the category IDs (don\u2019t forget the minus signs in front of them). Choose your own categories to be excluded by finding the category ID. If you aren\u2019t sure how to do that, <a href=\"https:\/\/wpmudev.com\/blog\/how-to-find-the-ids-of-wordpress-categories-posts-pages-and-more\/\" target=\"_blank\">see this post<\/a>.<br \/>\n{code type=php}<br \/>\nfunction excludeCat($query) {<br \/>\nif ( $query-&gt;is_home ) {<br \/>\n$query-&gt;set(&#8216;cat&#8217;, &#8216;-3,-5,-23&#8217;);<br \/>\n}<br \/>\nreturn $query;<br \/>\n}<br \/>\nadd_filter(&#8216;pre_get_posts&#8217;, &#8216;excludeCat&#8217;);<\/p>\n<p>Thanks to <a href=\"http:\/\/wp-snippets.com\/exclude-category-from-homepage\/\" target=\"_blank\">wp-snippets<\/a> for this very handy little piece of code.<\/p>\n<p>Photo credit: <a href=\"http:\/\/www.flickr.com\/photos\/wilhei\/109403306\/\" target=\"_blank\">Willi Heidelbach<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This little trick removes posts from specific categories from your homepage stream.<\/p>\n","protected":false},"author":84404,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[390],"tutorials_categories":[],"class_list":["post-117923","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-code"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/117923","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/84404"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=117923"}],"version-history":[{"count":1,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/117923\/revisions"}],"predecessor-version":[{"id":204518,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/117923\/revisions\/204518"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=117923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=117923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=117923"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=117923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}