Hello There,
The main content and the sidebar are two separate loops in displaying post items. The main content will display the recent blog items. This code will alter the main query.
function x_exclude_cat_from_blog($query) {
if ($query->is_home() && $query->is_main_query()) {
$query->set('cat', '-78');
}
}
add_action('pre_get_posts', 'x_exclude_cat_from_blog');
This code cannot and will not include the sidebar because the sidebar widget category has an independent loop on its own. And that is why it is still displaying the category in the widget. You may add this code in your child theme’s functions.php file as well.
//Hide categories from WordPress category widget
function exclude_widget_categories($args){
$exclude = "78";
$args["exclude"] = $exclude;
return $args;
}
add_filter("widget_categories_args","exclude_widget_categories");
We would loved to know if this has work for you. Thank you.