Support » Themes and Templates » How to request container_class from wp_nav_menu

  • Resolved 550

    (@550-1)


    Hi,

    I’m currently trying to setup a custom nav walker that will use container_class from the menu as a prefix for the class names of the list items and children.

    $defaults = array(
    'menu'	          => '',
    'menu_class'	  => '',
    'menu_id'	  => '',
    'container'       => 'nav',
    'container_class' => 'nav-primary',
    'container_id'	  => '',
    'before'	  => '',
    'after'		  => '',
    'link_before'	  => '',
    'link_after'	  => '',
    'depth'		  => 0,
    'walker'          => new Custom_Nav_Walker(),
    'theme_location'  => 'primary',
    'items_wrap'	  => '<ul>%3$s</ul>',
    );
    wp_nav_menu( $defaults );

    The general idea is the walker will loop out the classes according to the container class name. Like so.

    <nav class="nav-primary">
      <li class="nav-primary__item"><a href="#">Link</a></li>
      <li class="nav-primary__item"><a href="#">Link</a></li>
      <li class="nav-primary__item"><a href="#">Link</a></li>
    </nav>

    Hopefully someone can help.

  • The topic ‘How to request container_class from wp_nav_menu’ is closed to new replies.