Removing a Specific Category from the Blog Page in WordPress

The code given below excludes posts from a specific category (with ID 84) from appearing on the blog page in WordPress. It uses the ‘pre_get_posts’ hook to modify the main query for the homepage.

function ts_exclude_category( $query ) {
    // Check if the query is for the homepage (is_home)
    if ( $query->is_home ) {
        // Exclude category with ID 'xx'
        $query->set('cat', '-84');
    }
    return $query;
}

// Add the function to the 'pre_get_posts' hook
add_filter('pre_get_posts', 'ts_exclude_category');