Advertisement
firoze

supported-description-in-menu-IN_WP

Mar 21st, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1.  
  2. <!-- call in template where menu will be display -->
  3. <?php $walker = new Menu_With_Description; ?>
  4. <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu', 'walker' => $walker ) ); ?>
  5.  
  6.  
  7. <!-- call in functions.php -->
  8. class Menu_With_Description extends Walker_Nav_Menu {
  9. function start_el(&$output, $item, $depth, $args) {
  10. global $wp_query;
  11. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  12.  
  13. $class_names = $value = '';
  14.  
  15. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  16.  
  17. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
  18. $class_names = ' class="' . esc_attr( $class_names ) . '"';
  19.  
  20. $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
  21.  
  22. $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
  23. $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
  24. $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
  25. $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
  26.  
  27. $item_output = $args->before;
  28. $item_output .= '<a'. $attributes .'>';
  29. $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
  30. $item_output .= '<br /><span class="sub">' . $item->description . '</span>';
  31. $item_output .= '</a>';
  32. $item_output .= $args->after;
  33.  
  34. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement