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.
Leave a Reply