function demo_exclude_category( $wp_query ) {
if ( ! is_admin() && ! is_search() && ! is_archive() ) {
// Add the category ID to an array of excluded categories. Add multiples like this - ( '5', 'ID' )
$excluded = array( '-1' );
// Note that this is a cleaner way to write: $wp_query->set('category__not_in', $excluded);
set_query_var( 'category__not_in', $excluded );
} // end if
}
add_action( 'pre_get_posts', 'demo_exclude_category' );