How to add a site-wide counter using WP Statistics plugin in WordPress

This post explains how to how to display post views for single posts using the WP Statistics Plugin in WordPress. Let's make it further. It's possible to add a counter for displaying the number of today's visitors, yesterday's visitors and total visits using the date stored in the WP Statistics plugin.

WP Statistics - WordPress site-wide counter

To make it worked, we need to create shortcuts for returning today's visitors, yesterday's visitors and so on. And then, we can add shortcodes to the sidebar. (It's also possible to add a counter displaying visit(or)s for "Last 7 days," "Last 30 days" and "Last 365 days."

For example, to display the number of today's visitors, you can create a shortcode function as follows:

function wpstatistics_totalvisitors(){
return number_format_i18n(wp_statistics_visitor('total', null, true));
}
add_shortcode('wptotalvisitors', 'wpstatistics_totalvisitors');

 


Leave a Comment