Will McLean
Process diary

“Disable” a WordPress post type archive page

Last modified: October 26, 2017
Created: October 16, 2017

We will not actually disable the page. As far as I can tell these cannot be disabled (please do let me know if they can). We will redirect it to the home page. Good practice, no, good for the user, no, time saving, yes. Please! If anyone has any ideas that would make this nicer please share.

function post_type_archive_template_redirect() {
    if( is_post_type_archive( 'post-type' ) ) {
        wp_redirect( home_url() );
add_action( 'template_redirect', 'post_type_archive_template_redirect' );

Source: https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect

This is a Knowledge Base post.