Redirect to First Child Page Using Genesis Framework
If you have a parent page, that should redirect to the first child page, you may use this snippet.
Create a new file named “go_to_first_child_template.php” in your theme directory.
Add the following content to the new file:
<?php
/*
Template Name: Redirect to first child page
*/
$args = array(
'child_of' => $post->ID,
'sort_column' => 'menu_order'
);
$child_pages = get_pages($args);
if ($child_pages) {
$first_child_page = $child_pages[0];
wp_redirect( get_permalink($first_child_page->ID) );
} else {
// Fallback, if there is no child page
genesis();
}
Now you have to select as page template for the desired parent page the Template “Redirect to first child page”. When somebody opens the URL of the parent page, the page template looks for possible childs and openes the first child page (use the order weight to modify child pages order). If there is a child page, WordPress redirects to the child page, otherwise, the parent page is shown (as fallback).
Related Posts
- Code to Change Page Layout Using Genesis Framework
- Install Sentry on Ubuntu 18.04 Using Nginx and Let's Encrypt Certificates
- Remove Page Title on Frontpage Using Genesis Framework
- Customize Breadcrumbs for Custom Post Types Using Genesis Framework
- Tutorial: Ubuntu 18.04 LAMP Setup for WordPress
- Default Options for Genesis Themes
- Change Number of Custom Post Type Posts per Page
- Add Archive Settings Page for Custom Post Types