I have this code in functions.php but it does not output the total number of members (something is wrong with it it breaks the site) in my "Right Now" dashboard. Is there a way to fix it?

function dashboard_wps_user_count() {
global $wpdb;
$users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");
   <tr class="first">
      <td class="first b b_pages"><a href="users.php"><? echo $users; ?></a></td>
      <td class="t pages"><a href="users.php">Members</a></td>
add_action( 'right_now_content_table_end', 'dashboard_wps_user_count');

Additional feature

Also is there a way to show how many authors are registered and how many subscribers are registered also in the "Right now " dashboard?

  • provide the debug information, coz this code is working file with my local wordpress installation with 2010 theme installed
    – Amit Kosti
    Commented Aug 1, 2012 at 19:39
  • @amit Parse error: syntax error, unexpected $end i have local setup also but something is off in this code i don't know why.
    – jimilesku
    Commented Aug 1, 2012 at 20:18
  • @amit removing this function removes the error! I placed it at the very end of the functions.php
    – jimilesku
    Commented Aug 1, 2012 at 20:24
  • try enclosing this code within <?php and ?> and see if works.. Which theme you're using ?
    – Amit Kosti
    Commented Aug 1, 2012 at 20:27
  • @amit I use custom theme, where did You place the code? I placed it exactly like I wrote in functions.php and it gives out $end error <?php doesn't work either! Do You know any other way to do this?
    – jimilesku
    Commented Aug 1, 2012 at 20:32

1 Answer 1


So here is the small snippet to show total number of users and all roles with user count. This code should go in the themes functions.php file.

The code uses count_user function to fetch the array and show it up on Right Now dashboard screen.

function wpse_60487_custom_right_now() {
    $users = count_users();
    echo '<table><tbody>';
    echo '<tr><td class="first b b_pages">'.$users['total_users'].'</td><td class="t pages"> total users</td></tr>';
    foreach($users['avail_roles'] as $role => $count)
    echo '<tr><td class="first b b_pages">'.$count.'</td><td class="t pages">'.$role.'</td></tr>';
    echo '</tbody></table>';

add_action( 'wpse_60487_custom_right_now', 'dashboard_wps_user_count');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.