Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carasmo/769a02a056d477d61c9ffdc08267431f to your computer and use it in GitHub Desktop.
Save carasmo/769a02a056d477d61c9ffdc08267431f to your computer and use it in GitHub Desktop.
Automatically remove password protected page from wp_list_pages wherever this function is used such as the genesis sitemap.
/** ======================================================================================
*
* Automatically Exclude Password Protected Pages
*
* Kudos: https://gist.github.com/bonny/5772054
* The original (linked above) uses an argument:
* wp_list_pages('title_li=&post_type=faqs&echo=0&exclude_password_protected=1')
*
======================================================================================= */
function ca_exclude_password_protected_pages($pages, $r) {
if ( is_admin() ) return;
for ( $i = 0; $i < sizeof( $pages ); $i++ ) {
if ( post_password_required( $pages[ $i ] ) ) {
unset( $pages[ $i ] );
}
}
return $pages;
}
add_filter( 'get_pages', 'ca_exclude_password_protected_pages', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment