Created
April 4, 2014 08:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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