ID; } allo_set_post_views($post_id); } add_action( 'wp_head', 'allo_track_post_views'); /** * Allo Get Post View * * @package Allo * @since 1.0 */ function allo_get_post_views($postID){ $count_key = 'allo_post_views_count'; $count = get_post_meta($postID, $count_key, true); if( $count == 0 ) { return esc_html__(' 0 ','allo'); } elseif( $count == 1 ) { return esc_html__(' 1 ','allo'); } return $count; } /** * Allo Post Column View * * @package Allo * @since 1.0 */ add_filter('manage_posts_columns', 'allo_posts_column_views'); function allo_posts_column_views($defaults){ $defaults['post_views'] = esc_html__('Views', 'allo'); return $defaults; } /** * Allo Post Custom View * * @package Allo * @since 1.0 */ add_action('manage_posts_custom_column', 'allo_posts_custom_column_views',5,2); function allo_posts_custom_column_views($column_name, $id){ if ($column_name === 'post_views'){ $count_key = 'allo_post_views_count'; $count = get_post_meta(get_the_ID(), $count_key, true); if( $count == 0 ) { echo esc_html__(' 0 ','allo'); } elseif( $count == 1 || $count == 2) { echo esc_html__(' 1 ','allo'); } else { echo esc_html($count); } } }