Bar separated navigation by extending Walker_Nav_Menu

You can use the menu order inside the item to see if it’s not first. If it isn’t have it draw the character before the anchor.

class Bar_List_Walker_Nav_Menu extends Walker_Nav_Menu {
    private $separator = " | ";
    function start_el(&$output, $item, $depth, $args) {
        if($item->menu_order > 1){
            $output .= $this->separator;
        }
        $attributes  = ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
        $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
        $output .= '<a'. $attributes .'>';
        $output .= apply_filters( 'the_title', $item->title, $item->ID );
        $output .= '</a>';
    }
}

Leave a Comment