Parent Page Redirect to Child Page without Code
-
Hi,
I was wondering how to redirect a parent page to the first child page without using code, as I have only just started working with Word Press.
I came across a forum that worked it out using code but i don’t understand where to put it or anything.
The code was:
1) Create a new template file and paste the following code into it:
<?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));
}
}
?>2) save and upload your new template into your theme directory.
3) Edit your Parent page and apply the “Page Template”.
Note: adding the page template is located down towards the bottom of the page.
my website is https://www.dkyogacentre.com and Im trying to make the Services page go directly to the Yoga Classes page.
If anyone could help that would be great.
Thanks
- The topic ‘Parent Page Redirect to Child Page without Code’ is closed to new replies.