How-To Guides and Blog

Add post views 👀 to your WordPress posts

NBH Support
No Comments

Today If you want to track a number of visits you can use hundreds of plugins that offer you with just that. But having a lot of plugins can both slow down your site and cause a potential vulnerability in the future.

That’s why I suggest you use as less plugins as possible, and for small things like this make changes directly  to your theme files.

NOTE: you should always make a backup before making any changes and have in mind that you will eventually have to update your theme/plugin and that update will probably remove all your customizations. Therefor you should use child themes for all theme-related modifications.

First and foremost, go to the functions.php file of the currently used theme of WordPress. Then copy the code below and add it to your functions.php file:

Then, copy the code below and paste it into single.php file in the while loop.

Next, copy the following code and paste it where you want to show the number of views

When it’s all done, you will see the post view like this:

add post views, Add post views 👀 to your WordPress posts, New Blog Hosting

You can also add a bit of style to it with CSS, as we did for this post, below the post title.

The above code is a slightly modified version of the GretaThemes‘s snippets.

Leave a Comment