Tech Tip Tuesdays: Output a list of pages that includes/excludes pages based on their title

Hello and welcome to our first Tech Tip Tuesday, MIGHTYminnow’s very own tips & tricks series. Stay tuned for more…

WordPress’ native wp_list_pages() function is great for doing just what it sounds like – outputting a clean list of pages with one line of code – but sometimes we need to do more.

The following code goes in your theme’s functions.php file and can be used to output a list of pages, in which pages are included or excluded if their title contains a specified “test string.”

post_title, 'test string') ) {

		$exclude_ids .= $page->ID . ',';

	}

}

// Output pages, excluding the ones with "test string" in their title
$args = array(
  'exclude' => $exclude_ids,
  'title_li'=> ''
);

wp_list_pages( $args );

?>

Leave a Comment

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

%d bloggers like this: