Skip to content

Instantly share code, notes, and snippets.

@ledovej
Created April 14, 2020 11:00
Show Gist options
  • Save ledovej/9fb4c6f032c93d6368c78aeea2b8356f to your computer and use it in GitHub Desktop.
Save ledovej/9fb4c6f032c93d6368c78aeea2b8356f to your computer and use it in GitHub Desktop.
Disables archives for post-types by 404 page or redirect
/* Disable archives pages */
add_action('template_redirect', 'my_disable_archives_function');
function my_disable_archives_function()
{
/* Conditional checks examples:
is_category()
is_tag()
is_date()
is_author()
is_tax()
is_search() ... */
// Return a 404 for all archive types, except the my_custom_post_type archive.
$post_types = array('my_custom_post_type');
if ( (is_archive() && !is_post_type_archive( $post_types )) )
{
global $wp_query;
$wp_query->set_404();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment