寫這篇文章的目的是看到百度知道里有人問起來,碰巧我漢化的一個主題 Askit 正好使用了這個功能,所以產生了寫此文的目的。

1 、首先你需要在 function.php 檔案內註冊自定義選單功能,一般新增如下程式碼即可:

register_nav_menus(array('main'))
當然很多主題都有類似的語句,我之所以說類似,是因為有的不是叫 main 。

Photobucket

選單描述|薇曉朵 WordPress 主題

2 、接下來要在 function.php 寫一個函式:
class My_Walker_Nav_Menu extends Walker_Nav_Menu {

	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 = 'color: rgb(51, 153, 51); ">. 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="'%20%20%20.%20esc_attr($item->url%20%20%20%20%20%20%20)%20.'"' : '';

		$item->description = trim($item->description);
		$description = ! empty($item->description) ? $item->description : 'Describe the page.';

		$item_output = $args->before;
		$item_output .= '<a'. $attributes .'>';
		$item_output .= $args->link_before;

		if (0 == $depth) { // If at topmost level, add a short description.
			$item_output .= '<span>' . apply_filters('the_title', $item->title, $item->ID) . '</span>';
			$item_output .= '<br />';
			$item_output .= '<span>' . $description . '</span>';
		} else { // Show only the menu name.
			$item_output .= apply_filters('the_title', $item->title, $item->ID);
		}

		$item_output .= $args->link_after;
		$item_output .= '</a>';
		$item_output .= $args->after;

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

}
3 、在 header.php 內加入選單呼叫:
<?php
	wp_nav_menu(array(
		'theme_location' => 'main',
		'container'      => false,
		'walker'         => new My_Walker_Nav_Menu()
	));
?>
4 、當然最後,別忘了修改 css 。
注意,有人說我安裝你說的方法,不行。那是因為你沒有定義選單描述。按下面方法進行:
外觀-選單-標題屬性