Post views without plugin

There are lots of plugins that keep count of your posts views, but they all tend to be quite advanced and do a lot more than you might need(which is true for most plugins in general too).

This simple, yet brilliant snippet posted by Kevin Chard over at WP-Snipp does exactly what we need, and nothing more. Follow the steps below to count and display the number of views a post has.

Add the snippet to functions.php and follow these instruction:

Add this to single.php, and make sure you paste in inside the loop.

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

Lastly, to display the number of views a post has, just add this where you want it to be displayed:

<?php echo getPostViews(get_the_ID()); ?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!