If your theme doesn’t have post view counter, this is the simplest way how to count post views in WordPress  without using any plugins.

  • Custom WP

Using this WordPress feature, you can keep track of your post and have clear picture what articles of your website are performing well, visitors wise.

How to count post views in WordPress without plugins

Hart of your WordPress website is function.php file, located in your current theme.

So find the functions.php file of the currently used theme of WordPress. Then copy the code below and paste it to this file.

//This function get number of post views
function cwp_get_post_view() {
    $count = get_post_meta( get_the_ID(), 'post_views_count', true );
    return "$count views";
}

// Function to save post view in your post meta
function cwp_set_post_view() {
    $key = 'post_views_count';
    $post_id = get_the_ID();
    $count = (int) get_post_meta( $post_id, $key, true );
    $count++;
    update_post_meta( $post_id, $key, $count );
}
function cwp_posts_column_views( $columns ) {
    $columns['post_views'] = 'Views';
    return $columns;
}
function cwp_posts_custom_column_views( $column ) {
    if ( $column === 'post_views') {
        echo gt_get_post_view();
    }
}
add_filter( 'manage_posts_columns', 'cwp_posts_column_views' );
add_action( 'manage_posts_custom_column', 'cwp_posts_custom_column_views' )

Now find the file in your theme who display your post. Some theme use index.php, others single.php, singular.php.

<?php cwp_set_post_view(); ?>

This pace of code will display number of posts views on your post page. You need to copy and paste this on you php file who display posts.

<?php cwp_get_post_view(); ?>

Custom Function Custom Post Loop WordPress
WordPress