Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi, better to write your own walker class that will be work with description and menu image plugin. And sorry for a long response, was busy.

    no writing own walker class wont work either.

    here it is

    public function start_el(&$output, $item, $depth, $args) {
    global $wp_query;
    $indent = ( $depth ) ? str_repeat( “\t”, $depth ) : ”;

    $class_names = $value = ”;

    $classes = empty( $item->classes ) ? array() : (array) $item->classes;

    $class_names = join( ‘ ‘, apply_filters( ‘nav_menu_css_class’, array_filter( $classes ), $item ) );
    $class_names = ‘ class=”‘ . esc_attr( $class_names ) . ‘”‘;

    $output .= $indent . ‘<li id=”menu-item-‘. $item->ID . ‘”‘ . $value . $class_names .’>’;

    $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 .’>’;
    $item_output .= $args->link_before . apply_filters( ‘the_title’, $item->title, $item->ID ) . $args->link_after;
    // $item_output .= $args->link_before . apply_filters( ‘the_title’, $item->description, $item->ID ) . $args->link_after;

    $item_output .= ‘
    <span class=”sub”>’ . $item->description . ‘</span>’;
    $item_output .= ”;
    $item_output .= $args->after;

    $output .= apply_filters( ‘walker_nav_menu_start_el’, $item_output, $item, $depth, $args );
    }

    This is not generating description why?

    suggest me a hook to show description that will work and compatible to show description of menu. Please

    Rafinkarki! Look at the walker class in /wp-includes/nav-menu-template.php. You could do something like this.

    if ( ! class_exists( 'My_Awesome_Walker' ) ) :
      class My_Awesome_Walker extends Walker_Nav_Menu {
    
      function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
        // ...
        if ( !empty( $item->description ) ) {
            $item_output .= '<span class="sub">' . esc_attr( $item->description ) . '</span>';
        }
        // ...
      }
    }

    And call the menu like this:

    wp_nav_menu( array(
    	// ...
    	'walker'         => new My_Awesome_Walker(),
    	// ...
    ));

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Description Field’ is closed to new replies.