Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #377963

    Hey
    I’m trying to set that when adding a class to a menu item it will add the class to the link itself instead of the li.
    I came to this code that does that:

    class class_attr_nav extends Walker {
    	function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
    		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
    
    		$class_names = $value = '';
    
    		$classes = empty( $item->classes ) ? array() : (array) $item->classes;
    		$classes[] = 'menu-item-' . $item->ID;
    
    		$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
    		$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
    
    		$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
    		$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
    
    		$attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
    		$attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
    		$attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
    		$attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
    		$attributes .= ! empty( $class_names )      ? ' class="'  . esc_attr( $class_names      ) .'"' : '';
    
    		$item_output = $args->before;
    		$item_output .= '<a'. $attributes .'>';
    		$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
    		$item_output .= '</a>';
    		$item_output .= $args->after;
    
    		$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
    	}
    }

    Even before enfold uses already a custom walker, I need somehow to implement it in here…

    I found that the walker is defined in helper-responsive-megamenu.php, right?
    Any idea what do I need to change in order to accomplish this?

    Thanks

    • This topic was modified 9 years, 3 months ago by Elliott.
    #378475

    Hi website2create!

    Are you doing this to style specific links? If so then you could just change the CSS your using. Perhaps something like this.

    .your_class > a { color: red; }
    

    Go ahead and send us a link to your page and take a screenshot highlighting exactly what your trying to do and we’ll give you the CSS to use.

    Best regards,
    Elliott

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.