PHP方式:将以下内容添加到函数中。php文件。过滤器nav\\u菜单\\u链接\\u属性:
add_filter( \'nav_menu_link_attributes\', \'my_menu_atts\', 10, 3 );
function my_menu_atts( $atts, $item, $args )
{
// Provide the id of the targeted menu item
$menu_target = 123;
// inspect $item
if ($item->ID == $menu_target) {
// original post used a comma after \'modal\' but this caused a 500 error as is mentioned in the OP\'s reply
$atts[\'data-toggle\'] = \'modal\';
$atts[\'data-target\'] = \'#myModal\';
}
return $atts;
}
jQuery方式:
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(\'#menu-item-365\').find(\'a\').attr(\'data-toggle\', \'modal\');
jQuery(\'#menu-item-365\').find(\'a\').attr(\'data-target\', \'#myModal\');
});
</script>