Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fengelz
Created March 21, 2012 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fengelz/2146067 to your computer and use it in GitHub Desktop.
Save fengelz/2146067 to your computer and use it in GitHub Desktop.
Redirect to first child in wordpress
/*if($post has condition) {
redirect_first_child($post->ID);
}*/
function redirect_first_child($post_id) {
$pagekids = get_pages("child_of=".$post_id."&sort_column=menu_order");
if ($pagekids) {
$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