How to Exclude Post Categories from a WordPress Loop

December 21, 2019 , I learned...
/** Exclude "Today I Learned" category from blog loop */
function exclude_category_posts( $query ) {
  if ( $query->is_home() && $query->is_main_query() ) {
    $query->set( 'cat', '-5' );
}
add_action( 'pre_get_posts', 'exclude_category_posts' );