Show number of pageviews for a given page

As of Koko Analytics version 1.3.7, you can use the [koko_analytics_counter] shortcode to show the number of visitors or pageviews for a given post on your site.

The shortcode takes 3 optional arguments:

  • days: Show count over the last N days. Defaults to “3650”.
  • global: Whether to show the global count (for the entire site) or for the current page only. Defaults to “false”.
  • metric: One of “visitors” or “pageviews”. Defaults to “visitors”.

For example, to show the number of visitors for only the current page over the last 10 years, you can simply stick to the defaults:

[koko_analytics_counter]

To show the number of pageviews to the current page over the last 30 days, you can set the days and metric argument.

[koko_analytics_counter days="30" metric="pageviews"]

To show pageviews across the entire site, set the global argument to true.

[koko_analytics_counter days="30" metric="pageviews" global="true"]

How to use the shortcode from theme files

You can use this shortcode from PHP code, like in your theme files, by calling the do_shortcode function that WordPress provides:

<?php echo do_shortcode('[koko_analytics_counter]'); ?>

Was this article helpful? Yes / No