add post views, Add post views to your WordPress posts
add post views, Add post views to your WordPress posts

Add post views to your WordPress posts

I will guide you how to count post views in WordPress without using plugins.

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

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.

Add comment

Do you have a
WordPress problem?

Select what best describes your goals:

Cart

HOLD ON!

Do you have a
WordPress problem?

Become a WordPress Pro
with our easy to follow guides .

Hire an Expert to quickly solve
any WordPress related task.

We use cookies to provide an awesome experience on our website. By continuing to use this site, you agree to our tasty cookies.
🍪 Accept Cookies