Sometimes we do not want our custom taxonomies to have archive pages. Lots of reasons for this, yet there doesn’t seem to be a good solution for this. I would love to see WordPress implement a ‘has_archive’ flag for taxonomies someday. Until then we can use this function to return a 404 for any taxonomy archives we do not want shown to users.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/** * Disable the taxonomy archive pages */ add_action('pre_get_posts', 'jb_disable_tax_archive'); function jb_disable_tax_archive($qry) { if (is_admin()) return; if (is_tax('tax-slug')){ $qry->set_404(); } } |