Hello,
I want to hide specific categories from the shop – two at the moment. I have tried literally every code on the internet but nothing seems to be working. The only code that works is:
Simple way to hide a category from everything except the admin backend:
In functions.php:
add_filter( 'get_terms', 'hide_category', 10, 1 );
function hide_category( $terms ) {
$new_terms = array();
foreach ( $terms as $term ) {
if ( $term->slug !== 'secret_category' ) {
$new_terms[] = $term;
} else if ( $term->taxonomy !== 'product_cat' || is_admin() ) {
$new_terms[] = $term;
}
}
return $new_terms;
}
If you want to only hide it from the shop, add || !is_shop() to the else if condition.
But this just hides one categorie, it doesn’t allow me multiple choices. I’ve read somewhere on this forum that i should disable: Theme settings-Shop->sidebar&page title->categories in page title.
Can you help?
Thank you,