Skip to content

Instantly share code, notes, and snippets.

@amilabandara
Created November 12, 2020 03:06
Show Gist options
  • Save amilabandara/c8511c192d1cf8a9de8e797db83fb0a6 to your computer and use it in GitHub Desktop.
Save amilabandara/c8511c192d1cf8a9de8e797db83fb0a6 to your computer and use it in GitHub Desktop.
Redirect wordpress parent page to first child page
<?php
/*
Template Name: Redirect To First Child
*/
if (have_posts()) {
while (have_posts()) {
the_post();
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
$firstchild = $pagekids[0];
wp_redirect(get_permalink($firstchild->ID));
exit;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment