I have registered three custom taxonomies. All three of these custom taxonomies are attached to my custom post type.
There is only one taxonomy out of the three registered, that I would like not accessible what so ever on the frontend of the website.
What is the best solution for this?
I have been playing around with specifying different arguments while registering the taxonomy, but nothing seems to work.
$args['show_in_nav_menus'] = false;
$args['query_var'] = false;
$args['public'] = false;
Should I just hook into template_redirect
and do a is_tax()
check? If it’s the taxonomy I want disabled, just redirect to the custom post type archive?
s_ha_dum’s answer didn’t work for me, but this did:
WordPress taxonomy provides flexibilities to set its properties while registering it. To disable WordPress taxonomy archives, set “public” as “false” as shown in below example code. This will remove “View” action link from taxonomy screen and also redirect the user to website homepage when trying to access url of taxonomy manually.
Example
I’m not sure why @chris-herbert wrote it the way he did, but if you add this to your function file, this will force any navigation to that archive to go to your 404 page.
To guarantee that your taxonomy is never queried on the front end, you could strip it from all front end queries.
Using a closure should make the callback hard to remove.
You may also want to implement the redirect as you speculated but doing so wouldn’t prevent secondary queries in page templates or widgets from retrieving the taxonomy or could cause trouble if you try to redirect late in a page load.