Do you want to display total number of users in the “Right Now” dashboard widget? While there’s probably a plugin for this, we have created a quick code snippet that you can use to add total members to “Right Now” dashboard widget in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
function dashboard_wps_user_count() { global $wpdb; $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); ?> <table> <tbody> <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> </tr> </tbody> </table> <?} add_action( 'right_now_content_table_end', 'dashboard_wps_user_count');
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 28 best WordPress resume themes and how to create a WordPress donation form.
Hi Kein, Happy to land here!! 🙂
Thanks for this great snipp!
Is it possible to add custom post type count also? 🙂
This seems to have a number of issues Kevin. For those that may not know the <?} will throw an error. Also, "Members" on the dashboard doesn't show a count.
What issues are you having with the snippet?