• Skip to primary navigation
  • Skip to main content
  • Skip to footer
  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Content Modeling for WordPress
    • WordPress Hidden Gems
    • Web Design
  • Work
    • Presentations and Interviews
    • on GitHub →
    • MLIS Class Projects (2019-2022)
    • Portfolio (2002-2019)
    • WordPress Plugins

Stephanie Leary

Writer, Front End Developer, former WordPress consultant

  • About
    • Press Kit
    • Presentations and Interviews
  • Contact Me

Listing children on empty pages as a filter

June 3, 2010 Stephanie Leary Leave a Comment

Yesterday, I showed you how to automatically list child pages if a page’s content is empty. That code would go in your theme’s page.php file. What if you wanted to use it in any theme? The best solution is to turn it into a little plugin:

/*
Plugin Name: List Children on Empty Pages
Plugin Author: Stephanie Leary
*/

function append_child_pages($content) {
   $children = '';
   if (is_page() && (empty($content))) {
      global $post;
      $children = '
<ul class="childpages">'.wp_list_pages('echo=0&title_li=&child_of='.$post->ID).'</ul>
';
   }
   return $content.$children;
}
add_filter('the_content','append_child_pages');
?>

Paste the code into a file in your wp-content/plugins directory (something like append-child-pages.php), activate it, and it’ll work no matter which theme you choose.

WordPress Navigation, Posts and Pages

This is an excerpt from Content Strategy for WordPress.My latest books are Content Strategy for WordPress (2015) and WordPress for Web Developers (2013). Sign up to be notified when I have a new book for you.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer

My Books

I’m a front end developer at Equinox OLI, working on open source library software. I was previously a freelance WordPress developer in higher education. You can get in touch here or on LinkedIn.

Copyright © 2025 Stephanie Leary · Contact