How I Display Total Post View Count Without Any Plugin For WordPress?

How you see total post viewer in your blog post or individual post or page without any plugins. If You just copy and paste code from here to your theme function.php and single.php file. Then it will gives site all visitor and site admin the ability to quickly and simply see that how many people already visited that post. It is very simple and easy code for you. So, you just follow our instruction step by step below to count and display the total number of views. Here we work two file, a. function.php and b.single.php, now we open this two file and follow our simple instruction.

First Step: Copy below code and paste in your function.php file


//Display WordPress Post Views Count Without Any Plugin
function setBRPostViews($postID) {
    $count_key = 'views';
    $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);
    }
    return $count.' Views'; /* so you can show it */
}

Second Step: Copy the below code and paste in your single.php file where you see your view counts

echo setBRPostViews(get_the_ID())

​Leave a Comment

Comment authors age:




How to get the category title in a post in WordPress?

How to import too large database file in phpmyadmin?