Correct way to hide pseudo pages from being shown?

The homepage on a site we’ve developed has four pieces of content: the parent page and three further “pages” of text which we bring into the parent page using PHP. Call them Foo, Bar1, Bar2, Bar3 if you like.

Maybe this is or isn’t the correct way to solve the problem of a complex page but it works for us and for the client and he’s used to it now.

enter image description here

The small problem is that these pseudo-mini-pages Bar1, Bar2 and Bar3 are indexed by Google and can be served as pages in their own right. They don’t look terrible when served that way but we’d like to avoid it if possible.

I figure I can fix this by:

1) redirecting mysite/bar1 to mysite/foo in htaccess
OR
2) via our SEO plugin (Yoast) apply a robot noindex

But I’m asking here which approach is more correct or whether there’s a better way?

2 Answers
2

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