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:

inline

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.

Was this post helpful?

    Leave a Comment

    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
    Privacy Policy