Do you want to show the number of online users visiting your WordPress site? Online users widgets are fairly common for community sites and forums. In this article, we will show you how to display real time online users widget in WordPress.
First thing you need to do is install and activate the WP Useronline plugin. Upon activation, you need to visit Settings » UserOnline page to configure the plugin settings.
On this page, you can change the default plugin settings. These settings include time out, users online page URL, and display settings.
The default settings would work for most sites, so you need to just click on the save settings button at the bottom of the page.
The next step is to create the page where you want to showcase the users who are online right now on your WordPress site. Create a new WordPress page by going to Pages » Add New.
You can use any title for the page, but the page’s URL slug should be the same as you had in the plugin’s settings. Click on the edit button next to the URL slug and change it to useronline.
After that you need to add the shortcode
[page_useronline] in the content area. You can now publish this page.
Displaying Online Users on the Front-end in WordPress
The plugin provides two ways to display online users on your WordPress site. The first method is recommended for beginners. Simply go to Appearance » Widgets page. Next, drag and drop User Online widget from the list of available widgets to a sidebar.
The other method is to use this code in your theme files where you want to display users online.
<?php if (function_exists('users_online')): ?> <p>Users online: <div id="useronline-count"><?php users_online(); ?></div></p> <?php endif; ?>
Using the second method will allow you to use custom CSS to style it differently.
We hope this article helped you display the number of online users on your WordPress site. You may also want to take a look at out tutorial on how to add a private messaging system to your WordPress site.