change sub-menu class in wordpress

When using wp_nav_menu in my theme, I want to change Worpdress’ default sub-menu class for items that contain a child list (to dropdown to fit for the Foundation framework).

I have reviewed this post on the topic but I cannot seem to get it to function correctly.

Read More

In my functions.php file I have inserted:

class My_Sub_Menu extends Walker_Nav_Menu {
  function start_lvl(&$output, $depth) {
    $indent = str_repeat("t", $depth);
    $output .= "n$indent<ul class="dropdown">n";
  }
}

And in my header.php file I have:

<?php
    $defaults = array(
        'theme_location'  => 'header-nav',
        'menu_class'      => 'right',
        'walker'          => new My_Sub_Menu(),
        'container'       =>  false
    );
    wp_nav_menu( $defaults );
?>

But nothing occurs. Am I misunderstanding where to insert the code?

Related posts

Leave a Reply

1 comment

  1. Is it because you haven’t specified an end_lvl for your class My_Sub_Menu extends Walker_Nav_Menu?

    class My_Sub_Menu extends Walker_Nav_Menu {
      function start_lvl(&$output, $depth) {
        $indent = str_repeat("t", $depth);
        $output .= "n$indent<ul class="dropdown">n";
      }
      function end_lvl(&$output, $depth) {
        $indent = str_repeat("t", $depth);
        $output .= "$indent</ul>n";
      }
    }