Correct way to hide pseudo pages from being shown?

Well those are two different things:

  1. A redirect means they are not accessible any more at all.

  2. noindex just means that search engines ignore it while it is still accessible if you access the URL.

So I’d recommend option 1.
This is a simple way of doing this that you can improve an. (E.g. this expects to have a static front page set and doesn’t handle any other situation)

function wpse_211889_template_redirect()
{
    if ( ! is_page() ){
        return;
    }

    $frontpage_ID = get_option('page_on_front');

    global $post;
    if( $post->post_parent && $frontpage_ID === $post->post_parent )
    {
        wp_redirect( home_url() );
        exit();
    }

}
add_action( 'template_redirect', 'wpse_211889_template_redirect' );

Leave a Comment