• 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
    • MLIS Class Projects (2019-2022)
    • Portfolio (2002-2019)
    • Services
    • WordPress Plugins
    • WordPress Themes
    • Presentations and Interviews
    • on GitHub →

Stephanie Leary

Writer, WordPress consultant, recent MLIS grad

  • 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

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 © 2023 Stephanie Leary · Contact