Skip to content

Instantly share code, notes, and snippets.

@jayseventwo
Created September 30, 2013 01:32
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 jayseventwo/6758312 to your computer and use it in GitHub Desktop.
Save jayseventwo/6758312 to your computer and use it in GitHub Desktop.
Redirect main navigation link to subpage. To do this, Add this code to functions.php, create your main navigation page using this template, then add your selected pages as the sub-pages. When you now click on the main nav button it should redirect to your child page (or first subpage if more than one).
<?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));
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment