Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saroarhossain57/cb4b3c708ea35dbd7791521a93106f90 to your computer and use it in GitHub Desktop.
Save saroarhossain57/cb4b3c708ea35dbd7791521a93106f90 to your computer and use it in GitHub Desktop.
//this class will output the structure of the bootstrap nav menu.. we can also customize the walker class for our personal use.
class Primary_Walker_Nav_Menu extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
if ( array_search( 'menu-item-has-children', $item->classes ) ) {
$output .= sprintf( "\n<li class='dropdown %s'><a href='%s' class=\"dropdown-toggle\" data-toggle=\"dropdown\" >%s</a>\n", ( array_search( 'current-menu-item', $item->classes ) || array_search( 'current-page-parent', $item->classes ) ) ? 'active' : '', $item->url, $item->title );
} else {
$output .= sprintf( "\n<li %s><a href='%s'>%s</a>\n", ( array_search( 'current-menu-item', $item->classes) ) ? ' class="active"' : '', $item->url, $item->title );
}
}
function start_lvl( &$output, $depth ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul class=\"dropdown-menu\" role=\"menu\">\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment