[英]How to add <i> item if menu has sub-menu into wp_nav_menu
I have this type of menu, and I want this menu to convert into wp_nav_menu 我有这种类型的菜单,并且我希望此菜单转换为wp_nav_menu
<li><a href="#">menu ab</a></li>
<li ><a href="#">menu bc<i class="hover-ind fa fa-angle-down" aria-hidden="true"></i></a></li>
<ul class="sub-menu">
<li><a href="#">sub menu ab</a></li>
</ul>
As you can see if menu have submenu then I have to add <i></i>
code snippets to show down arrow with particular menu. 如您所见,菜单是否具有子菜单,那么我必须添加
<i></i>
代码段以显示具有特定菜单的向下箭头。
So I am trying, if menu has sub menu then add <i></i>
with anchor link into li
. 所以我正在尝试,如果menu有子菜单,那么将带有锚链接的
<i></i>
添加到li
。
I am able to add attributes to li
if menu has submenu by this code: 如果菜单具有此菜单的子菜单,我可以向
li
添加属性:
add_filter( 'nav_menu_link_attributes', 'wpse154485_add_aria_haspopup_atts', 10, 3 );
function wpse154485_add_aria_haspopup_atts( $atts, $item, $args ) {
if (in_array('menu-item-has-children', $item->classes)) {
$atts['aria-haspopup'] = 'true';
}
return $atts;
}
but I need add a <i></i>
code snippet if menu has submenu, Please help if anyone have clue about it. 但是如果菜单有子菜单,我需要添加一个
<i></i>
代码片段,如果有人对此有所帮助,请提供帮助。
TIA TIA
you need to modify the Walker_Nav_Menu
for adding your HTML markup. 您需要修改
Walker_Nav_Menu
来添加HTML标记。 check the GitHub link below for sample code. 查看下面的GitHub链接以获取示例代码。
https://github.com/wp-bootstrap/wp-bootstrap-navwalker https://github.com/wp-bootstrap/wp-bootstrap-navwalker
I have resolved this issue. 我已经解决了这个问题。 May be if someone looking for answer in future then my solution can help them.
可能是如果将来有人在寻找答案,那么我的解决方案可以为他们提供帮助。 here is I found a blog which is exactly for the solution for drop down indicator.
我在这里找到了一个博客,该博客正是针对下拉指示器解决方案的。 http://dksolution.in/add-dropdown-arrow-indicators-to-wordpress-menu-items-that-have-submenus/
http://dksolution.in/add-dropdown-arrow-indicators-to-wordpress-menu-items-that-have-submenus/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.