• Hi guys, i’ve a question about this code:

    $menu_name = 'main_menu';
    
    			if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
    			$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
    
    			$menu_items = wp_get_nav_menu_items($menu->term_id);
    
    			$menu_list = '<ul id="nav">';
    
    			foreach ( (array) $menu_items as $key => $menu_item ) {
    				$title = $menu_item->title;
    				$url = $menu_item->url;
    
    				$menu_list .= '<li><a title="' . $title . '" href="' . $url . '">' . $title . '<span>' . HERE COME THE TITLE ATTRIBUTE!!! . '</span></a></li>';
    			}
    			$menu_list .= '</ul>';
    			} else {
    			$menu_list = '<ul><li>Menu "' . $menu_name . '" not defined.</li></ul>';
    			}
    			// $menu_list now ready to output
    			echo ($menu_list);

    How can i show the “Title Attribute” situated in the Menus into the Appearance?? Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter cloix

    (@cloix)

    Someone??

    $menu_name = 'main_menu';
    if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
    $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
    
    $menu_items = wp_get_nav_menu_items($menu->term_id);
    //print_r($menu_items);
    
    $menu_list = '<ul id="nav">';
    foreach ( (array) $menu_items as $key => $menu_item ) {
    $title = $menu_item->title;
    $url = $menu_item->url;
    $title_alt = $menu_item->attr_title; // your attribute
    $menu_list .= '<li><a title="' . $title . '" href="' . $url . '">' . $title . '<span>' . $title_alt . '</span></a></li>';
    }
    $menu_list .= '</ul>';
    } else {
    $menu_list = '<ul><li>Menu "' . $menu_name . '" not defined.</li></ul>';
    }
    // $menu_list now ready to output
    echo ($menu_list);

    this worked for me, im not sure i put the title attribute where you wanted, but its there.

    to see all the attributes for the menu array un comment that print_r (not for production, just testing)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add the "Title Attribute" in the menu’ is closed to new replies.