How to completely disable a taxonomy archive on the frontend?

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?

4 s
4

s_ha_dum’s answer didn’t work for me, but this did:

/**
 * Completely disable term archives for this taxonomy.
 * @param  string $taxonomy WordPress taxnomy name
 */
function kill_taxonomy_archive($taxonomy){

    add_action('pre_get_posts', function($qry) {

            if (is_admin()) return;

            if (is_tax($taxonomy)){
                $qry->set_404();
            }

        }

    );

}

Leave a Comment