Created
December 13, 2021 16:39
-
-
Save spigotdesign/5d13c526fe1e4308458123fee53da2c3 to your computer and use it in GitHub Desktop.
Accessible WP menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Spigot_Walker extends Walker_Nav_Menu { | |
function start_el(&$output, $item, $depth=0, $args=array(), $id = 0) { | |
$object = $item->object; | |
$type = $item->type; | |
$title = $item->title; | |
$permalink = $item->url; | |
$classes = $item->classes; | |
$output .= "<li id='menu-item-". $item->ID ."' class='menu__item " . implode(" ", $classes) . "'>"; | |
if( $permalink && $permalink != '#' ) { | |
$output .= '<a class="menu__link" href="' . $permalink . '">'; | |
} else { | |
$output .= ''; | |
} | |
if($args->walker->has_children) { | |
$output .= '<button type="button" class="dropdown__title" aria-expanded="false" aria-controls="nav-dropdown-'. $item->ID .'">' ; | |
} | |
$output .= $item->title; | |
if($args->walker->has_children) { | |
$output .= '</button>' ; | |
} | |
if( $permalink && $permalink != '#' ) { | |
$output .= '</a>'; | |
} else { | |
$output .= ''; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment