The code 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 WordPress query on the homepage or blog listing page.
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');