Hide posts from selected category on main Wordpress page

Recently I wanted to display only one selected category on the main page. Fortunately I found an easy solution on the Don’t show a WordPress category on posts page blog post.

Steph created and added filter in the theme's functions.php file (hide category id: 13 in the example below):

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