create wordpress page template to redirect to first child page

June 9, 2009 · Print This Article

Many WordPress users uses parent pages and subpages to order the informations displayed on their blogs.

Then how to be able to redirect to the first child page if the current page have children pages?

You have to create a wordpress page template to redirect to first child page, Create a new file and paste the following code in it:


Template Name: Redirect To First Child
if (have_posts()) {
  while (have_posts()) {
    $pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
    $firstchild = $pagekids[0];

Save the file under the name redirect.php and upload it to the wp-content/themes/your-theme directory of your WordPress install. Once done, you can use the page template.

Your choice for site templates and wordpress themes


Got something to say?

You must be logged in to post a comment.