Can a user find a child page?

This is a shortcode you see there in the post/page content. It’s most likely displaying all the child pages (up to depth 1) of the current page. Shortcodes are very common, but you can’t see their output in the WordPress post/page editor, only on the front end where it’s generated via the do_shortcode() function.

The “hard” way:

So you can try do the following:

  1. Visit All Pages (/wp-admin/edit.php?post_type=page) in the backend.
  2. Locate the page that contains the [child-pages] shortcode.
  3. Locate it’s child pages (depth 1). See the screenshot below.
  4. Edit each child page to your needs.
  5. View the shortcode page again.
  6. Done.

Here are the child pages of depth 1 in the All Pages table:

Child pages of depth 1

The “easy” way:

We can use the following plugin to construct our own custom meta box that displays a list of all the current child pages.

Demo plugin:

<?php

/**
 * Plugin Name: Child Pages Meta Box
 * Description: Child pages meta box for hierarchial post types
 * Author:      Birgir Erlendsson (birgire)
 * Plugin URI:  http://wordpress.stackexchange.com/a/158636/26350
 * Version:     0.0.2
 */

function wpse_current_child_pages_meta_box()
{
    $post_types = get_post_types(); 
    foreach ( $post_types as $post_type )
    {
        if( is_post_type_hierarchical( $post_type ) )
        {
            add_meta_box(
                'wpse_child_pages',
                __( 'Current child pages' ),
                'wpse_list_current_child_pages',
                $post_type,
                'side',
                'low'
            );
        }
    }
}
add_action( 'add_meta_boxes', 'wpse_current_child_pages_meta_box' );

function wpse_list_current_child_pages( $post )
{
    $args = array(
        'child_of'      => $post->ID,
        'echo'          => 0,
        'title_li'      => '',
        'post_type'     => $post->post_type,
        'walker'        => new WPSE_EditLinks
    );
    $style="<style>.wpse_childpages li {margin-left: 15px;}</style>";
    $list = wp_list_pages( $args );
    if( ! $list )
        $list = sprintf( '<li>%s</li>', __( 'No child pages found!' ) );

    printf( '%s<ul class="wpse_childpages">%s</li>', $style, $list  );
}

class WPSE_EditLinks extends Walker_Page 
{
    function end_el( &$output, $page, $depth = 0, $args = array() )
    {       
        $edit_url  = admin_url( 'post.php?action=edit&post=" . $page->ID );
        $edit_link = " <a class="dashicons dashicons-edit' title="edit" href="" . esc_url( $edit_url ) . "" target="_blank"></a> ";
        $output = str_replace( "><a", ">". $edit_link. "<a", $output );
        $output .= "</li>\n";
    }
}

where we use wp_list_pages() to do all the hard work. But we only have to add the edit links, so that’s why we construct a custom Page walker.

This plugin will automatically activate the meta box on all post edit screens for every hierarchical post types.

Where do I add this code?

Create this subdirectory:

/wp-content/plugins/wpse-current-child-pages-metabox/

Then save the code snippet to the file:

/wp-content/plugins/wpse-current-child-pages-metabox/wpse-current-child-pages-metabox.php

and activate the plugin from the backend:

/wp-admin/plugins.php

Screenshots:

Here’s a screenshot of how it would work:

Current child pages

and with no child pages:

No child pages found!

Now you can just click on the edit link of the corresponding child page that you want to modify.

Much easier 😉

Gist/GitHub:

The plugin is availabe here on Gist/GitHub.