Plugin Directory

Test out the new Plugin Directory and let us know what you think.


Displays the most visited posts as a widget using data from Google Analytics. Designed to be used under high-traffic or low server resources.

Why should I use this plugin?

You should use this plugin if you want to display the most visited posts of your site in a safe and stable manner, with no risk of downtime or slowness, based on data from Google Analytics statistics. The plugin is built for high-traffic sites where counting every visitor's click loads up the DB and can potentially crash the site.

How often is the data from Google Analytics refreshed?

The data from GA is refreshed every hour. During this interval, the information is safely stored using transients and options.

How to use the custom template?

To use a custom template you just need to copy the file toplytics-template.php from Toplytics' plugin folder to your theme folder.

You can then customize your template. The plugin will first search for the file toplytics-template.php in the active theme folder, and, if that's not found, it will search for it in the plugin folder. The custom template from the theme folder has priority over the one in the plugin folder.

How can I use the shortcode?

The shortcode has 3 parameters: period -> default=month (today/week/month), numberposts -> default=5 (min=1/max=250), showviews -> default=false (true/false)

Shortcode example:

[toplytics period="week" numberposts="3" showviews="true"]

The shortcode can be used within post/pages and in other widgets from the sidebar. For any parameter that is not used, the default value will be used.

How can I use JavaScript code in order to show up the top in widget?

You can place the JavaScript code right in toplytics-template.php file or use a predefined JS code like this:

<script type="text/javascript">toplytics_results( toplytics_args  );</script>

The toplytics_args are the options from the current widget passed to the template. For a detailed example see the JavaScript code from js/toplytics.js file.

How can I use the plugin functionality outside the sidebar?

The plugin offers 2 functions that can be used either in the theme or by another plugin. Please review the complete documentation below.

1. toplytics_results


mixed toplytics_results( [ array $args ] )

toplytics_results() prints the toplytics results in <ol> format.


args -> This parameter is a list of toplytics options: period - represents the statistics period, default=month (today/week/month); numberposts - represents the number of posts to be displayed, default=5 (min=1/max=250); showviews - set this parameter to true if you want to print out the number of posts views, default=false (true/false);

Return Values

If the toplytics results will be printed, then the function returns TRUE, otherwise the return value is FALSE.


Here is a simple example that displays the first 7 most visited posts in the past month, toghether with the number of views:

    $toplytics_args = array(
        'period' => 'month',  // default=month (today/week/month)
        'numberposts' => 7,   // default=5 (min=1/max=250)
        'showviews' => true   // default=false (true/false)
    if ( function_exists( 'toplytics_results' ) )
        toplytics_results( $toplytics_args );

2. toplytics_get_results


mixed toplytics_get_results( [ array $args ] )

toplytics_get_results() returns the toplytics results into an array; in this case, the toplytics results' HTML can be formatted according with your needs.


args -> This parameter is a list of toplytics options: period - represents the statistics period, default=month (today/week/month); numberposts - represents the number of posts to be displayed, default=5 (min=1/max=250);

Return Values

If the toplytics results contains at least one element, the function will return an array with the toplytics results, otherwise the return value is FALSE.


    if ( function_exists( 'toplytics_get_results' ) ) {
        $toplytics_args = array(
            'period' => 'month',  // default=month (today/week/month)
            'numberposts' => 3    // default=5 (min=1/max=250)
        $toplytics_results = toplytics_get_results( $toplytics_args );
        if ( $toplytics_results ) {
            $k = 0;
            foreach ( $toplytics_results as $post_id => $post_views ) {
                echo (++$k) . ') <a href="' . get_permalink( $post_id )
                    . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">'
                    . get_the_title( $post_id ) . '</a> - ' . $post_views . ' Views<br />';

The outcome will look like this:

1.) This is the most visited post - 123 Views

2.) This is the second most visited post - 99 Views

3.) This is the third most visited post - 12 Views

How to change the data ranges?

You can use the filter toplytics_ranges in order to change the default ranges (today/week/month).

Example 1

Here is a simple example that adds year range:

add_filter( 'toplytics_ranges', 'toplytics_add_on_ranges' );
function toplytics_add_on_ranges( $ranges ) {
    $ranges['year'] = date_i18n( 'Y-m-d', strtotime( '-364 days' ) );
    return $ranges;

Example 2

Here is a simple example that removes all ranges except month:

add_filter( 'toplytics_ranges', 'toplytics_add_on_ranges' );
function toplytics_add_on_ranges( $ranges  ) {
    if ( ! empty( $ranges['month'] ) ) {
        $new_ranges['month'] = $ranges['month'];
        return $new_ranges;
    return $ranges;

What is `toplytics.json` file?

This file contains the statistics in JSON format, and is designed to be used with the JS custom template code.

Where is `toplytics.json` file located?

The file toplytics.json is located to the root folder of the site.


If the site domain is http://www.example.com/ then the file url is http://www.example.com/toplytics.json.

Requires: 3.9 or higher
Compatible up to: 4.6.2
Last Updated: 3 weeks ago
Active Installs: 100+


5 out of 5 stars


3 of 4 support threads in the last two months have been marked resolved.

Got something to say? Need help?


Not enough data

0 people say it works.
0 people say it's broken.