Display page list when no menu is assigned
Use this function to automatically add wp_list_pages to an empty menu location. You only need to call this function where you are calling wp_nav_menu and add the fallback: ‘fallback_cb’ => ‘wpc_default_menu’,
/** * Snippet Name: Display page list when no menu is assigned * Snippet URL: https://wpcustoms.net/snippets/display-page-list-menu-assigned/ */ function wpc_default_menu( $args = array() ) { $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => ''); $args = wp_parse_args( $args, $defaults ); $args = apply_filters( 'faq_default_menu_args', $args ); $menu = ''; $list_args = $args; // Show Home in the menu if ( ! empty($args['show_home']) ) { if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) $text = __('Home', 'omega'); else $text = $args['show_home']; $class = ''; if ( is_front_page() && !is_paged() ) $class = 'class="current_page_item"'; $menu .= '