Skip to content

Instantly share code, notes, and snippets.

@alexstandiford
Last active November 4, 2016 10:16
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 alexstandiford/a03615c2ddefa5974955bb6e66d24f60 to your computer and use it in GitHub Desktop.
Save alexstandiford/a03615c2ddefa5974955bb6e66d24f60 to your computer and use it in GitHub Desktop.
Basic Nav Menu Walker Structure for custom WordPress themes.
<?php
class myWalker extends Walker_Nav_Menu {
// Displays start of a level. E.g '<ul>'
// @see Walker::start_lvl()
function start_lvl(&$output, $depth=0, $args=[]) {
$output .= '<ul>';
}
// Displays end of a level. E.g '</ul>'
// @see Walker::end_lvl()
function end_lvl(&$output, $depth=0, $args=[]) {
$output .= '</ul>';
}
// Displays start of an element. E.g '<li> Item Name'
// @see Walker::start_el()
function start_el(&$output, $item, $depth=0, $args=[]) {
$output.= '<li>'.esc_attr($item->title);
}
// Displays end of an element. E.g '</li>'
// @see Walker::end_el()
function end_el(&$output, $item, $depth=0, $args=[]) {
$output .= '</li>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment