Skip to content

Instantly share code, notes, and snippets.

@jimmy89Li
Created November 30, 2017 14:00
Show Gist options
  • Save jimmy89Li/8cabf6d360bfe008624c304af8116895 to your computer and use it in GitHub Desktop.
Save jimmy89Li/8cabf6d360bfe008624c304af8116895 to your computer and use it in GitHub Desktop.
WP nav menu excluding pages with specific template
<nav class="navmenu">
<?php
$args = array( 'post_type' => 'page', 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => array( array( 'key' => '_wp_page_template', 'value' => 'page-gallery.php', 'compare' => '=', ) ), );
$pages_to_exclude = new WP_Query( $args );
wp_page_menu( array( 'before' => '<ul class="sf-menu">', 'sort_column' => 'menu_order, ID', 'menu_class' => 'primary-menu', 'exclude' => implode( ',', $pages_to_exclude->posts ), ) );
?>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment