# Send Empty Parent Pages to Their First Child Page

> When a parent page has no content of its own (it only groups subpages in the menu), visitors who open it are sent to its first child page instead of a blank page.

- Type: PHP
- Runs: Run everywhere
- Category: [Redirects](https://wpide.com/library/category/redirects/)
- Tags: pages, redirect, navigation
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/empty-parent-page-to-first-child/

## Code

```php
add_action( 'template_redirect', function () {
    if ( ! is_page() || is_front_page() ) {
        return;
    }

    $page = get_queried_object();

    if ( ! $page instanceof WP_Post || '' !== trim( $page->post_content ) ) {
        return;
    }

    $children = get_posts( array(
        'post_type'   => 'page',
        'post_parent' => $page->ID,
        'post_status' => 'publish',
        'orderby'     => array( 'menu_order' => 'ASC', 'title' => 'ASC' ),
        'numberposts' => 1,
    ) );

    if ( $children ) {
        wp_safe_redirect( get_permalink( $children[0] ), 302 );
        exit;
    }
} );
```

## Notes

Only pages whose content is completely empty are redirected; the first child is chosen by menu order, then title. The redirect is temporary, so adding content later works right away.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Send Empty Parent Pages to Their First Child Page" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
