Skip to content

Instantly share code, notes, and snippets.

@marcjenkins
Created September 17, 2013 16:11
Show Gist options
  • Save marcjenkins/6596572 to your computer and use it in GitHub Desktop.
Save marcjenkins/6596572 to your computer and use it in GitHub Desktop.
WordPress template that directs page to first child.
<?php
/* Template Name: Redirect */
?>
<?php
$args = array('child_of'=>get_the_ID(), 'sort_column'=>'menu_order', 'sort_order'=>'ASC');
$pages = get_pages($args);
$first_child = $pages[0]->ID;
$link = get_permalink($first_child);
?>
<?php
header("HTTP/1.1 301 Moved Permanently");
header('Location: '.$link);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment