/* Disable Category Archives WordPress, Redirects to 404 */
add_action('template_redirect', 'wpflt_remove_wp_category_archives');
function wpflt_remove_wp_category_archives(){
if( is_category() ) {
global $wp_query;
$wp_query->set_404();
}
}
WordPress Category Archive URL: https://example.com/category/category-name/
If you are not using any Categories, or using WordPress for Single Page site or as an Ecommerce Website, you should disable Category Archives. Above code redirects Category Archives to 404 Page.
Below code to functions.php redirects WordPress Category Archive URL to Homepage.
/* Disable Category Archives WordPress, Redirects to Homepage */
add_action('template_redirect', 'wpflt_remove_wp_category_archives');
function wpflt_remove_wp_category_archives(){
if( is_category() ) {
$target = get_option('siteurl');
$status = '301';
wp_redirect($target, 301);
die();
}
}