admin管理员组文章数量:1294763
I have to add a bubble notification in WordPress wp_nav_menu
like the following code.
<ul>
<li> Tickets <span class="unread">2</span></li>
<li> Log-out</li>
</ul>
Here I have to add this part in it.
<span class="unread">2</span>
I have seen this one and tried it.
add_action( 'walker_nav_menu_start_el', 'wpse_10042_nav_menu_post_count', 10, 4 );
function wpse_10042_nav_menu_post_count( $output, $item, $depth, $args ) {
$output .= '<span class="unread">'.my_function_here().'</span>';
return $output;
}
And get it from here How to add post count to wp_nav_menu?
But the problem is its adding to every menu link. I want to add it to only one menu item. Not everyone in the list.
I have to add a bubble notification in WordPress wp_nav_menu
like the following code.
<ul>
<li> Tickets <span class="unread">2</span></li>
<li> Log-out</li>
</ul>
Here I have to add this part in it.
<span class="unread">2</span>
I have seen this one and tried it.
add_action( 'walker_nav_menu_start_el', 'wpse_10042_nav_menu_post_count', 10, 4 );
function wpse_10042_nav_menu_post_count( $output, $item, $depth, $args ) {
$output .= '<span class="unread">'.my_function_here().'</span>';
return $output;
}
And get it from here How to add post count to wp_nav_menu?
But the problem is its adding to every menu link. I want to add it to only one menu item. Not everyone in the list.
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Nov 24, 2015 at 12:29 KvvaradhaKvvaradha 9363 gold badges12 silver badges24 bronze badges 02 Answers
Reset to default 4For flexibility, you could assign the CSS bubblecount class to the corresponding menu item:
and then target it with:
if( in_array( 'bubblecount', (array) $item->classes ) )
$output .= '<span class="unread">'.my_function_here().'</span>';
in your code snippet above.
How about just
function add_bubble_to_nav( $items, $args ) {
$items .= '<span class="unread">stuff</span>';
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_bubble_to_nav', 10, 2 );
No need to use walker here, just go for the filter I think.
This adds it to the end of the menu. If you need it in a specific position you could go for strpos
to find the position and then substr_replace
to put it in there or something.
本文标签: commentsHow to add bubble count in WordPress wpnavmenu menu
版权声明:本文标题:comments - How to add bubble count in WordPress wp_nav_menu menu? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741596914a2387467.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论