Need help with custom menu-walker
-
My PHP skills are poor so i can’t do it myself so maybe here you can help me.
What i want to do is to apply off-canvas from this codepen https://codepen.io/designsoutheast/pen/ZYERGo to JointsWP theme. Both are Foundation 5 based but JointsWP display off-canvas in different multi-level menu. ( see https://foundation.zurb.com/docs/components/offcanvas.html#off-canvas-multilevel-menuAnd this is menu-walker i need to edit
class Offcanvas_Walker extends Walker_Nav_Menu { function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { $element->has_children = ! empty( $children_elements[ $element->ID ] ); $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : ''; $element->classes[] = ( $element->has_children && 1 !== $max_depth ) ? 'has-submenu' : ''; parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); } function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { $item_html = ''; parent::start_el( $item_html, $object, $depth, $args ); $classes = empty( $object->classes ) ? array() : (array) $object->classes; if ( in_array( 'label', $classes ) ) { $item_html = preg_replace( '/<a[^>]*>(.*)<\/a>/iU', '<label>$1</label>', $item_html ); } $output .= $item_html; } function start_lvl( &$output, $depth = 0, $args = array() ) { $output .= "\n<ul class=\"left-submenu\">\n<li class=\"back\"><a href=\"#\">". __( 'Back', 'jointstheme' ) ."</a></li>\n"; } }
It would be nice if i could only replace classes but not all of them are would be generated in the same place (has-submenu in div and off-canvas-submenu-call need to be in a href).
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Need help with custom menu-walker’ is closed to new replies.