メニューには、タイトル属性というフィールドが存在し、値をセットすることが出来ますが、メニューにタイトル属性は表示されません。
タイトル属性を追加するには、フィルターを使うと便利です。
Note:
$atts['class']= 'tooltip';
このクラスの追加は、Raindropsテーマ用のクラス設定です。
Raindropsテーマでは、WordPressのタイトル属性は表示しないといった慣習を尊重して、リンクタグにタイトル属性が存在する場合でも、明示的にtooltipというクラスが存在しない場合、ツールチップを表示しないように工夫しています。a要素以外の場合には、タイトル属性が存在すればツールチップが表示されます。
<?php
add_filter( 'nav_menu_link_attributes', 'my_nav_menu_attr_add', 10, 3 );
function my_nav_menu_attr_add( $atts, $item, $args ) {
if ( ! empty( $item->attr_title ) ) {
/**
* Add title attribute for a element
*/
$atts['attr_title']= esc_attr( $item->attr_title );
/**
* Raindrops
* To display the value of the title attribute with the tooltip with the a element,
* the raindrops theme needs the tooltip class.
*/
$atts['class']= 'tooltip';
return $atts;
}
return $atts;
}
?>