You have an extra , at the end. Try:
has_category( 'sports' ) || is_category( 'sports' )
Great that worked. Do you you know how to get it to work w/ a custom taxonomy? I’m using this has_term( ‘camden’, ‘town’ ) || is_town( ‘Camden’ ) and it works for the archive and a post that have that taxonomy. but then when i go to my site, the page is blank except for the lines of the menu.
I think you’re getting a fatal error as is_town is not a function. For that you have to use the is_tax function (info: https://codex.ww.wp.xz.cn/Conditional_Tags#A_Taxonomy_Page_.28and_related.29):
has_term( 'camden', 'town' ) || is_tax( 'town', 'camden' )
I’ve looked thru these forums, but couldnt find how to hide a menu for certain taxonomies. I found how to hide for pages, but that code doesnt to be working on my site. I am using this currently – ! has_term( ‘camden’, ‘town’ ) || ! is_tax( ‘town’, ‘camden’ ) to try to hide a menu item if the page or post has the town taxonomy of camden. It is not working.
Since you want the menu to show on neither of those conditions you have to use && operator, or use parentheses to clarify the !, like so:
! ( has_term( 'camden', 'town' ) || is_tax( 'town', 'camden' ) )
Above snippet will hide the menu item if has_term or is_tax conditions are met.
-
This reply was modified 7 years, 10 months ago by
shazdeh.
I found this code in a different comment to show if a parent category, but its for product category. how do i translate it for my custom ‘town’ taxonomy’? I have several child taxonomies of a parent taxonomy and i want menus items to show / hide if posts are in any of the child taxonomies.
has_term( get_terms( array( ‘child_of’ => 69, ‘taxonomy’ => ‘product_cat’, ‘fields’ => ‘names’ ) ), ‘product_cat’ )