How To Show Views Count In Every Post - Wordpress
Want to show views count on each of your posts ?, Yes the easiest possible way is waiting your way scroll down. 1) Firstly, go to the Functions.php file of the currently used theme of WordPress. Then copy the code below and paste it (at the end usually) before the closing tag?> of the Functions.php file. function gt_get_post_view() { $count = get_post_meta( get_the_ID(), 'post_views_count', true ); return "$count views"; } function gt_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 gt_posts_column_views( $columns ) { $columns = 'Views'; return $columns; } function gt_posts_custom_column_views( $column ) { if ( $column === 'post_views') { echo gt_get_post_view(); } } add_filter( 'manage_posts_columns', 'gt_posts_column_views' ); add_action( 'manage_posts_custom_column', 'gt_posts_custom_column_views' ); 2) Then, copy the code below and paste it into single.php file in the while loop. find the image below for reference - 3) Next, copy the following code and paste it where you want to show the number of views. 4) Now, Paste the below code in function.php file under INC folder i.e. "inc/function.php", See the below pictures to know where to place the code in "function.php" file. 4. When it’s all done, you will see the post view like this: Read the full article














