Show Post Views Count on Posts Without Any Plugin in WordPress
Some premium themes comes with post view count features. We can use same features on our WordPress blog also but it needs plugins for show. But you not like plugin like me then you can try my 2nd alternative method for show post view count on website. It is php code method you need edit your theme php files. You can see that every theme show author name on post so we can show post view count also there so that we avoid additional CSS coding for post views count in well manner.
First open you functions.php and enter this code with in php tag.
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
return $count.' Views';
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}Now open your single.php file and enter this code
<?php setPostViews(get_the_ID()); ?>
see pic below I insert this code in my file. In this pic you can see that I insert code after while(have_posts().
This code only for initialize function in single.php file now you need to show post view count. For show post view counts use below code.
<?php echo getPostViews(get_the_ID()); ?>I use this code near author show code and now my code is same like this:<div class=”postdate”><span class=”sadmin”><?php _e(‘Posted by’,THEME_LANG_DOMAIN); ?> <?php the_author(); ?> <?php _e(‘on’, THEME_LANG_DOMAIN); ?> <?php the_time(‘F jS Y’) ?> <?php _e(‘in’,THEME_LANG_DOMAIN); ?> <?php the_category(‘, ‘) ?> <?php edit_post_link(__(‘edit’,THEME_LANG_DOMAIN)); ?> <?php comments_popup_link(__(‘No Comment’,THEME_LANG_DOMAIN), __(’1 Comment’,THEME_LANG_DOMAIN), __(‘% Comments’,THEME_LANG_DOMAIN)); ?> <?php echo getPostViews(get_the_ID()); ?></span>
</div>
After apply this code on my theme result is:
I put <?php echo getPostViews(get_the_ID()); ?> this code after comment show code. You can use this code on your home page also for show post views of every post. If you feel any problem for implement this code on your theme then please comment below.

ty very much!!
- another plugin hater (:
I am having problem in Praven option theme
dude just help, its just working on my firefox Browser, no other browser working with this trick
First of all it is not a trick it is php code and php codes always shows in all browsers. I am using Firefox, IE and Chrome in all post view count showing well. I think clear your browser cache before check it on your website. If any problem pls comment here.
Thank you very much. How to use this with activated cache plugin?
This works fine … but I want to bring up counter for a few days, months, weeks too, how to make it??
dude.. need help! I used this code and it works but the count of views are jumping by 2 counts and everytime i refresh my browser the its still counting even if i did not view the video.
someone knows to troubleshoot pls help me. thanx…
Please send me your files via email at sandeeprhce5[at]gmail[dot]com. I will check them for errors.
Does this work with WP-SuperCache and where are the postviews actually being stored?
Yes you can use it WP-SuperCache and all value will store on your database of WordPress
Thanks for this tips, but i wanna ask you something.
How to put 1st the message and after the counts.
You have like this (example) :
69 Views
I want like this (example) :
Views : 69
~Regards~
Sandeep, This code is working fine for my blog!! As you mentioned that all values is going to be stored in DB. Could please tell me which table it is going to update the view count?