Skip to content

Instantly share code, notes, and snippets.

@chasereeves
Created July 16, 2012 18:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chasereeves/3124135 to your computer and use it in GitHub Desktop.
Save chasereeves/3124135 to your computer and use it in GitHub Desktop.
Wordpres Custom Menu/Navigation Walker - remove all list items from menu, only links remain.
//========================================================== CUSTOM MENU WALKER - remove list stuff, only links
class custom_menu_walker_remove_list extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
$class_names = ' class="' . esc_attr( $class_names ) . '"';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
$id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$item_output = $args->before;
$item_output .= '<a'. $attributes. $id . $class_names .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
function end_el( &$output, $item, $depth = 0, $args = array() ) {
$output .= "\n";
}
}
<p id="main_menu"><?php wp_nav_menu( array('menu' => 'Main Menu', 'container' => '', 'theme_location' => 'primary', 'items_wrap' => '%3$s', 'walker'=> new custom_menu_walker_remove_list() )); ?></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment