On a site that I'm working on I have a particular page that has four subpages, which act like process steps. I want the parent page to always redirect to the first of these as a default, should the user type in or click on a url that only points to the parent page. Is there a way to accomplish this without the use of mod_rewrite? Thanks in advance.


You can try something like this. This will check if a page has child pages and if it does then it will redirect the first page in array ordered by menu order.

// get child pages
$child_page = get_pages( "child_of=" . $post->ID . "&sort_column=menu_order" );

if ( $child_page ) {

    // get id of first child page
    $firstchild = $child_page[0];
    wp_redirect( get_permalink( $firstchild->ID ) );

  • Ah, didn't know about wp_redirect. Thanks! – Staffan Estberg Sep 4 '14 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.