Skip to content

Instantly share code, notes, and snippets.

@ashucg
Last active May 5, 2017 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashucg/2e932164b80bf2f21c7b0f461a9f2726 to your computer and use it in GitHub Desktop.
Save ashucg/2e932164b80bf2f21c7b0f461a9f2726 to your computer and use it in GitHub Desktop.
Foundation 6 Menu for WP extending Walker class
<?php
class FoundationMenu 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 ) ? 'has-dropdown' : '';
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 );
$output.= ( $depth == 0 ) ? '<li class = "divider"></li>' : '';
$classes = empty( $object->classes ) ? array ( ) : ( array ) $object->classes;
if( in_array( 'label', $classes ) ){
$output.= '<li class = "divider"></li>';
$item_html = preg_replace( '/<a[^>]*>( .* )<\/a>/iU', '<label>$1</label>', $item_html );
}
if ( in_array( 'divider', $classes ) ){
$item_html = preg_replace( '/<a[^>]*>( .* )<\/a>/iU', '', $item_html );
}
$output.= $item_html;
}
function start_lvl( &$output, $depth = 0, $args = array ( ) )
{
$output.= "<ul class=\"menu vertical dropdown\" data-dropdown-menu>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment