If you look at several websites, then you will see that there is an option which helps you to know the exact post view on that posts. And this is most popular interesting things for the readers. It grabs your visitor attention within a few seconds.
The total post view function highlighted them in a very important way. Because if a visitor can also see your own blog post view count on your website then generally, they will assume that it is very important and people are reading it seriously.
If you are looking the same function for your website then this post is only for you. In this post, I’ll show you how you can display your total post views on your WordPress website.
However, there is two different way you can use one of them for complete the process. The first one is Use a plugin and the Second one is Use Raw code. But if you beginner then I’ll recommend you to go with free useful plugins.
Display Post Views using a free plugin:
Although there are lots of useful free post views plugin that you can use on your website. And the great news is every single plugin are available in the WordPress directory. I listed here top number one Free post views counter Plugins for you.
1. Post Views Counter
I put this plugin in the first place in this post because It’s one of the most popular and useful post views counter plugins that I have ever seen. Right now the total active install is 70,000+
It has good reviews that almost 4.9 out of 5. That’s really awesome. Post views counter is very fast useful and well-organized plugin. It supports any kind of WordPress themes. It has lots of features including sortable admin column, Multisite compatible, WP SuperCache and many more.
The post views work automatically and it counts of views depends on the behavior of visitors on your website. So you don’t have to do anything for adding the total view on your post.
However, if you don’t want or if you don’t care about accuracy then you can change the post views counts manually. Post views counter has a great option that will help you to change the number of views and to make a post more or less popular.
The installation process is very easy. You have to need just install and activate this plugin then you will see a dashboard for post Views counter then you have to need to configure some easy settings.
Let’s see how you can display the post views without any plugin:
To display the post view counts is easy to use a plugin and this is the best way. But there is some webmaster they usually use the raw code for adding any new function to their website.
And this section is for them, who know the WordPress more than a beginner and know properly how WordPress functions works.
Step: 1
However, it’s not so difficult to do this. It’s a very simple process. At first, go to the “Appearance” from your dashboard then select the “Editor” option and then open the functions.php file (you will find the file on the right side of the editor) then put the following code into the functions.php file.
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);
}
}
// Remove issues with prefetching adding extra views
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
Step: 2
Now in the second step add the following code into your single.php file within the loop. This will track the views and display into every single post.
setPostViews(get_the_ID());
Step: 3
Now you are almost done. This is the last step in this process. Now its time to set the post views counter number position into the post. You have to need to put this code properly and the exact place where you want to show the number of views.
echo getPostViews(get_the_ID());
Kudos to Wpsnipp for creating such useful snippet.
Conclusion
I hope this article is helpful for you and it completes your requirements. Let us know if you have any question. Also if you know any plugin that works well for post view counts then you can recommend us.