# Child Pages List Shortcode

> Adds a [child_pages] shortcode that lists the subpages of the current page, so section landing pages always link to everything below them.

- Type: PHP
- Runs: Run everywhere
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: shortcode, pages, navigation
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/child-pages-shortcode/

## Code

```php
add_shortcode( 'child_pages', function ( $atts ) {
    $atts   = shortcode_atts( array( 'id' => 0, 'depth' => 1, 'sort' => 'menu_order' ), $atts, 'child_pages' );
    $parent = $atts['id'] ? absint( $atts['id'] ) : get_the_ID();

    if ( ! $parent ) {
        return '';
    }

    $list = wp_list_pages( array(
        'child_of'    => $parent,
        'depth'       => absint( $atts['depth'] ),
        'title_li'    => '',
        'echo'        => false,
        'sort_column' => in_array( $atts['sort'], array( 'menu_order', 'post_title', 'post_date' ), true ) ? $atts['sort'] . ', post_title' : 'menu_order, post_title',
    ) );

    return $list ? '<ul class="wpide-child-pages">' . $list . '</ul>' : '';
} );
```

## Notes

Use [child_pages id="12" depth="2"] to list the children of another page or to include grandchildren.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Child Pages List Shortcode" 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/
