我有一个自定义菜单:
function mfn_wp_nav_menu() {
$args = array(
'container' => 'nav',
'container_id' => 'menu',
'menu_class' => 'menu',
'fallback_cb' => 'mfn_wp_page_menu',
'depth' => 5,
'link_before' => '<span>',
'link_after' => '</span>',
);
}
HTML中的输入是:
<li id="id" class="class">
<a href="#" data-hash="">
<span>Start</span>
</a>
</li>
但我想添加data-letters =“Link name”,例如:
<li id="id" class="class">
<a href="#" data-hash="">
<span data-letters="Start">Start</span>
</a>
</li>
任何想法?
答案 0 :(得分:0)
您可以像这样扩展Walker菜单类:
asp:SqlDataSource
并将其应用到您的菜单中:
class MyMenu extends Walker {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$output .= sprintf( "\n<li><a href='%s'%s><span data-letters='%s'>%s</span></a></li>\n",
$item->url,
( $item->object_id === get_the_ID() ) ? ' class="current"' : '',
$item->title,
$item->title
);
}
}
请参阅参考资料中的此示例:here