Get post view without any plugin in WordPress
Follow the steps given bellow
- Go to your theme’s function.php and add the following code in it.
$count_key = ‘post_views_count’;
$count = get_post_meta($postID, $count_key, true);
if($count==”){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, ‘0’);
return “0 View”;
}
return $count.’ Views’;
}
function setPostViews($postID) {
$count_key = ‘post_views_count’;
$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);
}
}
remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0);
- This step tracking the view of the post so post the following code in single.php where you want to display the post views.
?>
3 Comments
nice
ReplyDeleteNice knowledge gaining article. This post is really the best on this valuable topic. Brizy review
ReplyDeletePress organization Reuters utilizes WordPress to stay up with the latest with the most recent news as it occurs. Music gushing administration Spotify powers its whole site with WordPress. neuronto deepl wordpress plugin
ReplyDelete