Display wp_list_pages with dynamicly created exclude list

Twenty Sixteen Review

Adding the first snippet to the functions.php of your wordpress theme will use wp_list_pages but filter out any pages that contain no content creating an excluded_pages array. Then add the second snippet into your wordpress theme in the location you wish to display the pages.

function wps_wp_list_pages(){
$excluded_pages = array();
$all_pages = get_pages();
foreach ( $all_pages as $the_page ) {
    if ('' == $the_page->post_content) {
        $excluded_pages[] = $the_page->ID;
wp_list_pages( array(
    'exclude' => implode(',',$excluded_pages)
<? wps_wp_list_pages(); ?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!