In my journey back to WordPress, there are lots of little modifications I need to make the website my own. One of which is the addition of micro and link posts.
I do not like all posts showing in the main RSS feed nor on the main index page of my blog. Many options and guides tell you to install plugins or add in code to your functions to exclude categories to all feeds. If you can avoid a plugin, then I would advise it, to prevent any unnecessary loading of your blog.
I did stumble on a solution to my requirements on Stack Overflow (where else), and this is detailed below.
add_action(‘pre_get_posts’, ‘exclude_category’ ); function exclude_category( &$wp_query ) // Exclude from loop, archive and feed but not from category page/feed { if( is_home() || ( is_feed() && !is_category() ) || ( is_archive() && !is_category() )) { // Exclude from home, feed, but not from category page/feed set_query_var(‘category__not_in’, array(120)); // Exclude category with ID 120 } }
Add this to your themes functions.php file and remember to change the (‘category__not_in’, array(120)
to your desired category ID , if you need help finding that, check out this guide.
Leave A Reply Instead?
Read Comments (0)