If you have ever used or just visited a forum, you have probably noticed a counter which shows how many users are online at the given moment. Depending on the forum or the website, this counter can look different. Usually, it shows how many users are online and how many of those are registered users, i.e. how many are just guests.
While WordPress by default doesn’t have the feature installed, you can still track the number of online users by using a simple plugin.
WP UserOnline is a free plugin which can show you exactly what you need. Not only you can display the number of online people, but this plugin will tell you where they are on your website and will divide them into categories – Members, Guests, and Searchbots.
Install the plugin and set it up:
- Go to Plugins->Add New
- Search for “WP-UserOnline”, install and activate the plugin
- Navigate to Settings->UserOnline
This is where you can set up your plugin. You can set the time in seconds after which the online user will be removed from the database and thus removed from the list of online users. Choose a different URL for the UserOnline page where the information is displayed and choose if you want to link usernames with the author pages.
After that, you can change the text which represents users, members, guests, and bots. This is useful if you run a site in a different language or simply want to use other nomenclature in the English language.
- Save changes
- Go to Pages->Add New
- Choose a name
- Make sure to open Text Editor and paste the following shortcode:
- Save changes
You can choose page name that you want, but the important part is to match the URL to one in the plugin settings from step #3. If you didn’t change settings in the plugin, your new page must have URL like this one:
This is how your page might look like:
Set up the widget:
That’s it. If you open the page you have just created, you should see there is at least one active user on the site – that’s you.
If it’s not only you who needs to see the number of online users, you should make the page visible to everyone. A simple way of doing this is already integrated into the plugin – it’s a widget.
- Navigate to Appearance->Widgets
- Find User Online widget
- Drag and drop it in the widget area where you want the counter to appear
- Choose a title
- Choose a counter type
There are few different statistics you can show:
- Users online count
- Users browsing the current page
- Users browsing your site
- Users online count + users browsing the current page
- Users online count + users browsing your site
- Save changes
If you want to place the counter somewhere else in your theme, you will need the following code:
<?php if (function_exists('users_online')): ?> <p>Users online: <div id="useronline-count"><?php users_online(); ?></div></p> <?php endif; ?>
Enjoy your new feature, but if you want an even easier solution, check out 5sec Who’s Online plugin.