
通常、ディスクリプションを表示したい…はずですし、全部表示したく無ければ管理メニューのチェックボックスを、外せば良いんです。
じゃあ、どうしてこれをやりたかったかと言うと、ガラケー(またの名をフューチャーフォン)用の表示だけ、ディスクリプション出したく無かったのです。
だって、ガラケー、もといフューチャーフォンで表示した時に、訳が分からないじゃないですか、だから消したかったのです。
え、今更、ガラケー?と思われた方…私もつい数ヶ月前までそう思っていました。が、お客様曰く(ネットショップ経営)、まだいらっしゃるとのこと。
使用者としては、かなり多いらしいのですが、どれくらいのガラケーユーザーが、サイトを見たり、ショップを使用しているかは不明です。
しかし、作らなければなりません……。
ちなみに、携帯用の表示はKtai Styleです。
そして、function.phpに下記のコードを足します。
/***************************************************************************/
/* メニューのデスクリプションを削除
/***************************************************************************/
class non_description_walker extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
$output .= $indent . '<li' . $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 .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'non_description_walker', $item_output, $item, $depth, $args );
}
}
そして、任意の場所に。
<?php wp_nav_menu( array ( 'theme_location' => 'header-navi', 'walker' => new non_description_walker() ) ); ?>
‘theme_location’ => ‘header-navi’
の、’header-navi’の部分には
functions.phpのメニューを有効にする時に指定したものを入れましょう。
// カスタムメニューの「場所」を設定
register_nav_menu( ‘header-navi’, ‘ヘッダーのナビゲーション’ );
の名前です。
これで、ディスクリプションが出なくなります。




