Skip to content

Instantly share code, notes, and snippets.

@rob-gordon
Created November 3, 2016 15:10
Show Gist options
  • Select an option

  • Save rob-gordon/89559b05975a7a4a0cd57c339afb9b9f to your computer and use it in GitHub Desktop.

Select an option

Save rob-gordon/89559b05975a7a4a0cd57c339afb9b9f to your computer and use it in GitHub Desktop.
Wordpress Template Redirect
<?php
/* In a filenamed template-first-child.php */
/*
Template Name: Go to first child
*/
?>
<?php
/* In functions.php */
function redirect_template() {
if (get_page_template_slug() == 'template-first-child.php') {
global $post;
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
wp_redirect(get_permalink($pagekids[0]->ID));
exit();
}
}
add_action( 'pre_base_load', 'redirect_template', 100 );
?>
<?php
/* At the top of the base.php template */
use Roots\Sage\Setup;
use Roots\Sage\Wrapper;
do_action( 'pre_base_load' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment