Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save annalinneajohansson/9970232 to your computer and use it in GitHub Desktop.
Save annalinneajohansson/9970232 to your computer and use it in GitHub Desktop.
Exclude pages with meta value 'hide_page_in_menus' set to 1 from wp_list_pages
add_filter( 'get_pages', 'hip_exclude_from_wp_list_pages', 10, 2 );
/**
* Exclude pages with meta value 'hide_page_in_menus' set to 1 from wp_list_pages
* @param array $pages
* @param array $args
* @return array $pages
*/
function hip_exclude_from_wp_list_pages( $pages, $args ) {
// Check for 'walker' key to see if this is being used by wp_list_pages()
if( array_key_exists( 'walker', $args ) ) {
foreach ( $pages as $key => $item ) {
$hide_page = get_post_meta( $item->ID, 'hide_page_in_menus', true );
if( $hide_page == 1 ) unset( $pages[$key] );
}
}
return $pages;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment