When you build your own website using WordPress, if you want to display the page views of each article on the website, you will generally use a WordPress page views plug-in, which can conveniently count the page views of each article on our website.

First, add the following code to the wordpress template function functions.php file in the website backend:
/*Show article views*/
function getPostViews($postID){
$count = get_post_meta($postID,’views’, true);
if($count==”){
delete_post_meta($postID,’views’);
add_post_meta($postID,’views’, ‘0’);
return “0”;
}
return $count.”;
}
function setPostViews($postID) {
$count = get_post_meta($postID,’views’, true);
if($count==”){
$count = 0;
delete_post_meta($postID,’views’);
add_post_meta($postID,’views’, ‘0’);
}else{
$count++;
update_post_meta($postID,’views’, $count);
}
}
It can be used wherever you need to display the number of views, including the homepage, category page, and article page.
Add the call code for the number of views:
<?php setPostViews(get_the_ID()); echo number_format(getPostViews(get_the_ID())); ?>