Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress redirection page template to the first child page (menu_order) with WPML handling
<?php
/**
* Template Name: Redirect to child page
* Description: Redirects to the top child page
*
* @package PUT YOUR THEME NAME HERE :D
*/
global $post;
$parent = $post->ID;
// In case you use WPML
if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
$_type = get_post_type( $post->ID );
$parent = icl_object_id( $post->ID, $_type, true, ICL_LANGUAGE_CODE );
}
$post_children = get_children( array(
'posts_per_page' => 1,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => 'page',
'post_status' => 'publish',
'post_parent' => $parent
) );
wp_redirect( get_permalink( array_pop( $post_children )->ID ), 301 );
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.