php - displaying the function result on a menu -


i wondering if it's possible display value returned function on main menu in wordpress? figured can use custom links display text on menu. call function calculates number of users online , display result on menu.

something chinesepod.com does

here's code calculating 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 target single link on menu giving class (user-number in case).

the theme location defined register_nav_menus function

register_nav_menus( array(         'primary' => __( 'primary menu',      'twentyfifteen' ),         'social'  => __( 'social links menu', 'twentyfifteen' ),     ) ); 

here target primary menu location, target social menu.

function so30559666_nav_description( $item_output, $item, $depth, $args ) {     if ( 'primary' == $args->theme_location && in_array("user-number", $item->classes)) {         $count = ray_number_online_users();         $item_output = str_replace( $args->link_after . '</a>', '<div class="menu-user-count">' . $count . '</div>' . $args->link_after . '</a>', $item_output );     }      return $item_output; } add_filter( 'walker_nav_menu_start_el', 'so30559666_nav_description', 10, 4 ); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -