• I am looking at a site that uses a custom walker menu. The submenu works but a 2nd level submenu does not. I’m not sure if this is an issue with the walker script or with the css.

    The walker script is

    <br />
    //Custom Menu Walker<br />
    class Custom_Walker_Nav_Menu extends Walker_Nav_Menu {<br />
    	function start_lvl(&$output, $depth) {<br />
    		$indent = str_repeat("\t", $depth);<br />
    		$output .= "\n$indent<div class='drop'>
    <ul>\n";<br />
    	}</p>
    <p>	function end_lvl(&$output, $depth) {<br />
    		$indent = str_repeat("\t", $depth);<br />
    		$output .= "$indent</ul>
    </div>\n";<br />
    	}</p>
    <p>	function start_el(&$output, $item, $depth, $args) {<br />
    		global $wp_query;<br />
    		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';</p>
    <p>		$class_names = $value = '';</p>
    <p>		$classes = empty( $item->classes ) ? array() : (array) $item->classes;<br />
    		$classes[] = 'menu-item-' . $item->ID;</p>
    <p>		$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );<br />
    		$class_names = ' class="' . esc_attr( $class_names ) . '"';</p>
    <p>		$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );<br />
    		$id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';</p>
    <p>		$output .= $indent . '<li' . $id . $value . $class_names .'>';</p>
    <p>		$attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';<br />
    		$attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';<br />
    		$attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';<br />
    		$attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';</p>
    <p>		$item_output = $args->before;<br />
    		if(strpos($class_names, 'notlink')){<br />
    			$item_output .= '<span class="link">';<br />
    			$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;<br />
    			$item_output .= '</span>';<br />
    		}else{<br />
    			$item_output .= '<a'. $attributes .'>';<br />
    			$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;<br />
    			$item_output .= '';<br />
    		}</p>
    <p>		$item_output .= $args->after;</p>
    <p>		$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );<br />
    	}</p>
    <p>	function end_el(&$output, $item, $depth) {<br />
    		$output .= "\n";<br />
    	}<br />
    }<br />

    and it’s being called via

    wp_nav_menu (array('container' => false,
    'theme_location' => 'primary',
    'menu_id' => '',
    'menu_class' => 'navigation',
    'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s',
    'walker' => new Custom_Walker_Nav_Menu)
    );

    The site is

    https://cmcb.org

    Thanks,

  • The topic ‘Custom Walker Menu – Depth Issue’ is closed to new replies.