Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i'am currently using latest version of jetpack. So the stats plugin is also included in this plugin. But now i want to display the number of views the single post get on the single.php file using the data from Stats plugin included in jetpack. So how can i do this?

share|improve this question

1 Answer 1

Put this into your functions.php file:

function userfunc_get_post_views($postID) {
        global $post_stats;
        foreach ( $post_stats as $p ) {
            if ( $p['post_id'] == $postID ) { ?>
                <span class='stats-post-views'>
                    <?php echo number_format_i18n( $p['views']) . ' views'; ?>
        <?php }

and then into your single.php file where you want the views to be displayed:

<?php userfunc_get_post_views(get_the_ID()); ?>

This will wrap it in a div with the class of stats-post-views so you can style it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.