Hide category from homepage

Hi There,
I’m trying to hide several categories from home page.
I add this code on function.php:
// Exclude category from homepage.
function my_exclude_category( $query ) {

if ( $query->is_home ) {
$query->set( ‘cat’, ‘-5’, ‘-16’ );

return $query;

add_filter( ‘pre_get_posts’, ‘my_exclude_category’ );

…but it desn’t work. It’s a scpecific problem of Illdy theme?
Thank you so much

Hi There
Hope you are having a good day and thank you for your question :slight_smile:
I just tested the sample code and it seems to be working just fine. Is it possible that you have some other code that could be causing this issue? Kindly try testing it without any other plugin installed and let me know how it goes.
Colorlib Support Team

I tried but it still doesn’t work.
I will find the way.
Thank you so much

hey there

There are other methods to utilize, check this out: