dragunoff

wpquestions.com, ID = 2880

Aug 24th, 2011
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. // set nav item classes to an empty array
  2. function filter_nav_menu_classes( $classes ) {
  3.  
  4.     // create array for new classes
  5.     $new_classes = array();
  6.    
  7.     // return the new array with classes
  8.     return $new_classes;
  9.  
  10. }
  11.  
  12. add_filter( 'nav_menu_css_class', 'filter_nav_menu_classes' );
  13.  
  14.  
  15. // custom walker for the nav menu
  16. class clean_html_walker extends Walker_Nav_Menu
  17. {
  18.     function start_el(&$output, $item, $depth, $args) {
  19.         global $wp_query;
  20.         $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  21.  
  22.         $class_names = $value = '';
  23.  
  24.         $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  25.         $classes[] = 'menu-item-' . $item->ID;
  26.  
  27.         $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
  28.         $class_names = !empty( $class_names ) ? ' class="' . esc_attr( $class_names ) . '"' : '' ; // print out the attribute if the array with classes is not empty
  29.        
  30.         $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
  31.         $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
  32.  
  33.         $output .= $indent . '<li' . $id . $value . $class_names .'>';
  34.  
  35.         $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
  36.         $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
  37.         $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
  38.         $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
  39.  
  40.         $item_output = $args->before;
  41.         $item_output .= '<a'. $attributes .'>';
  42.         $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
  43.         $item_output .= '</a>';
  44.         $item_output .= $args->after;
  45.  
  46.         $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment