Skip to content

Instantly share code, notes, and snippets.

@wpbean
Created July 6, 2016 21:19
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 wpbean/580d977cf5a2d0619cf0ffc8e9a3399b to your computer and use it in GitHub Desktop.
Save wpbean/580d977cf5a2d0619cf0ffc8e9a3399b to your computer and use it in GitHub Desktop.
<?php
class WPB_WMCA_Nav_Walker extends Walker_Nav_Menu{
function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ){
$id_field = $this->db_fields['id'];
if ( is_object( $args[0] ) ) {
$args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
}
return parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
}
function start_el( &$output, $item, $depth, $args ) {
if ( $args->has_children ){
$attributes .= ' href="#"';
}elseif( ! empty( $item->url ) ){
$attributes .= ' href="' . esc_attr( $item->url ) .'"';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment