First add get_the_categories
filter before the_category(' , ')
then remove it. So it will not effect categories on other places.
add_filter( 'get_the_categories', 'remove_selected_categories' );
the_category(' , ');
remove_filter( 'get_the_categories', 'remove_selected_categories' );
In callback function check for categories to remove then remove them!
function remove_selected_categories( $categories ) {
$categories_to_remove = array(
'years',
'genere'
); //Place the slug for categories
foreach ($categories as $index => $single_cat) {
if (in_array($single_cat->slug, $categories_to_remove)) {
unset($categories[$index]);
}
}
return $categories;
}
Check the documentation for get_the_categories filter.