Created
April 14, 2020 11:00
-
-
Save ledovej/9fb4c6f032c93d6368c78aeea2b8356f to your computer and use it in GitHub Desktop.
Disables archives for post-types by 404 page or redirect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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