Do you want to WordPress post views counter without Plugin? Here are your right tutorials. Basically, You can add post views Counter With plugin but Someone Don’t like add any plugin. however, Today I will show You how to make Post views counter Just Three Steps.
Let’s Started.
At first, go to your theme editor and selected (function.php)
Then Just Paste below Code in the (function.php) save.
<?php // function to display number of posts. 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.' '; } // function to 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); } } ?>
Then You need go to Single.php and Paste below Code and Save.
<?php setPostViews(get_the_ID()); ?>
Final Step Paste This below Code where You want to Show Post Counter.
<?php echo getPostViews(get_the_ID()); ?> views
Thanks for reading post.If you have any problem.Please drop your problem on comment box.
Leave a Reply