CustomPress: Taxonomy with no archives

Is there a way to create a taxonomy which has an admin UI but does not have archive pages on the frontend?

There doesn't seem to be an option for this?

Failing that, any custom snippet I can put into my functions file to disable the frontend pages for these taxonomies?

  • Denitsa

    Hello there Shaun,
    I hope you're having a beautiful day and thank you for your question!

    You can check the following function which will disable all archives for the taxonomy it is called with

    /**
     * Completely disable term archives for this taxonomy.
     * <a title=param href=/profile/param>param</a>  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();
                }
            }
        );
    }

    Another solution (it will hide archives for all taxonomies) would be simply

    /* Register template redirect action callback */
    add_action('template_redirect', 'wpmu_remove_tax_archives');
    
    /* Remove archives */
    function wpmu_remove_tax_archives(){
       if( is_tax() ) {
        global $wp_query;
        $wp_query->set_404(); //set to 404 not found page
      }
    }

    Tell me how these work for you!

    All the best,
    Denitsa