How to redirect 404 of custom posts type in WordPress

2018 / 05 / 08

You can redirect 404 of  a custom post to a specific page by following snippet.


add_action( 'template_redirect', 'your_post_redirect' );

function your_post_redirect()
    // check if is a 404 error, and on your custom post type
    if( is_404() && is_singular('your-custom-post-type') )
        // then redirect to yoursite.com/some-page/
        wp_redirect( home_url( '/some-page/' ) );


Hi, I am a full-stack web developer with 5+ years of experience in working with different web technologies. Do you want to ask something? just send me a message through the contact form. Please visit my portfolio at hamzamehmood.com. Thanks