-1

The following code outputs a menu but the container <nav> tag is missing.

$menu_settings = array(
    'menu' => 'Packages',
    'container' => 'nav',
    'container_class' => '',
    'container_id' => '',
    'menu_class' => 'menu',
    'menu_id' => '',
    'echo' => true,
    'fallback_cb' => 'wp_page_menu',
    'before' => '',
    'after' => '',
    'link_before' => '',
    'link_after' => '',
    'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    'depth' => 0,
    'walker' => '',
    'theme_location' => 'primary' );

?>

      <?php wp_nav_menu( $menu_settings ); ?>

These are registered in functions.php:

register_nav_menus( array(
 'primary' => __( 'Packages Menu', 'nameoftheme'),
 'secondary' => __( 'Services Menu', 'nameoftheme' ),
) );

Only a <ul> with list items is rendered. List items are also not wrapped.

5
  • 1
    Please properly indent your code. On smaller screens most of your code is out of bounds and thus unreadable :-) – Pieter Goosen Feb 6 '15 at 7:46
  • Done. Should point out though that less reasonable developers might balk at being told to 'indent properly' :-) – codecowboy Feb 6 '15 at 7:52
  • That is true, but again it is up to them if they want to be helped. Most users like me are on small screen devices like mobile phones, and if code is not properly indented or added, we can't read it and therefor just ignore the question. As a developer you should know just how frustrating it is to read code and debugging it if it has format issues. :-) This is just my thoughts and a tip. It is true, the readability of a question does influence the amount of positive feedback you get back – Pieter Goosen Feb 6 '15 at 7:59
  • Code seems to be ok. Just tried it out and it does spit out the nav container, and wrapped up items as well. – yivi Feb 6 '15 at 8:12
  • Does this still happen, after you disabled all plugins and switched to one of the Twenty* themes? Please follow the linked process to identify the conflicting plugin or theme. – kaiser Feb 10 '15 at 8:37
1

As I am using the roots theme framework, this line removes the container argument:

function roots_nav_menu_args($args = '') {
  $roots_nav_menu_args = array();
  $roots_nav_menu_args['container'] = false;
  if (!$args['items_wrap']) {
    $roots_nav_menu_args['items_wrap'] = '<ul class="%2$s">%3$s</ul>';
  }
  if (!$args['depth']) {
    $roots_nav_menu_args['depth'] = 2;
  }
  return array_merge($args, $roots_nav_menu_args);
}
add_filter('wp_nav_menu_args', 'roots_nav_menu_args');
1
  • This can now be found in Soil: add_theme_support('soil-nav-walker'); – Sven Dec 5 '18 at 5:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.