Display the second or third level menu items in WordPress

Surprisingly WordPress does not have the feature to only display second or third level menu items. The following script will let you display the second or third level menu items by using a fantastic plugin called “wp_nav_menu Extended!” by Junaid Bhura.

Steps to get this working:

  1. Sign into WordPress
  2. Install the plugin
  3. Use the following code to display the menu. The following checked if there is a third or second level menu items present.
default_menu_level_two = array(
      'menu' => 'main',
      'level' => 2,
      'child_of' => (int)$GLOBALS['wpse16243_title'],
      'container'       => '',
      'container_class' => '',
      'menu_id'    => 'subsite-menu',
      'menu_class'      => 'subsite-menu hidden-md-down',
      'items_wrap' => '<div class="subsite-menu-container"><ul id="%1$s" class="%2$s">%3$s</ul></div>',
      'echo' => FALSE,
  );

  $sub_menu_one = wp_nav_menu( $default_menu_level_two );
  $default_menu_level_three = array(
      'menu' => 'main',
      'level' => 3,
      'child_of' => (int)$GLOBALS['wpse16243_title'],
      'container'       => '',
      'container_class' => '',
      'menu_id'    => 'subsite-menu',
      'menu_class'      => 'subsite-menu hidden-md-down',
      'items_wrap' => '<div class="subsite-menu-container"><ul id="%1$s" class="%2$s">%3$s</ul></div>',
      'echo' => FALSE,

  );

$sub_menu_two = wp_nav_menu( $default_menu_level_three );

if(!empty ( $sub_menu_one )){
 echo $sub_menu_one;
}else if(!empty ( $sub_menu_two )){
 echo $sub_menu_two;
}

wp_reset_query();