Created
November 3, 2016 15:10
-
-
Save rob-gordon/89559b05975a7a4a0cd57c339afb9b9f to your computer and use it in GitHub Desktop.
Wordpress Template Redirect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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