How to hide posts from selected category on the main WordPress page

Hide posts from the selected category on the main WordPress page.

Create a filter in the theme functions.php file (for example hide category id 13).

function exclude_category($query) {
  if ( $query->is_home )
    $query->set('cat', '-13');
  return $query;
}
add_filter('pre_get_posts', 'exclude_category');