I was wondering if it’s possible to display value returned from a function on the Main Menu in WordPress? I figured I can use custom links to display text on the menu. Now I would like call a function which calculates the number of users online and display the result on the menu.
Something like chinesepod.com
does
Here’s the code for calculating the number of users : –
function ray_number_online_users() {
$i = 0;
if ( bp_has_members( ‘user_id=0&type=online&per_page=999&populate_extras=0′ ) ) :
while ( bp_members() ) : bp_the_member();
$i++;
endwhile;
endif;
return $i;
}`
The easiest way to target a single link on your menu is by giving it a class (user-number in this case).
The theme location is defined by the register_nav_menus function
Here I target the
primary
menu location, but I could also target thesocial
menu.