Skip to content

Instantly share code, notes, and snippets.

@biswajitpaul01
Created February 3, 2018 18:20
Show Gist options
  • Save biswajitpaul01/dc888a6fb8077bee4febe75be7f159f6 to your computer and use it in GitHub Desktop.
Save biswajitpaul01/dc888a6fb8077bee4febe75be7f159f6 to your computer and use it in GitHub Desktop.
Wordpress Nav Menu Walker
<?php
if ( ! class_exists( 'Snowflakes_Walker_Menu' ) ) {
class MyTheme_Walker_Menu extends Walker_Nav_Menu {
/**
* At the start of each element, output a <li> and <a> tag structure.
*
* Note: Menu objects include url and title properties, so we will use those.
*/
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$item->classes = ( $item->object_id === get_the_ID() ) ? array_push( $item->classes, 'current' ) : $item->classes;
$output .= sprintf( "\n<li class='%s'><a title='%s' class='nav-link' href='%s' %s>%s</a></li>\n",
implode(' ', $item->classes),
$item->title,
$item->url,
$item->target ? 'target="'. $item->target .'"' : '',
$item->title
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment