{"id":30200,"date":"2023-12-05T12:55:18","date_gmt":"2023-12-05T07:55:18","guid":{"rendered":"https:\/\/mcstarters.com\/blog\/?p=30200"},"modified":"2024-01-10T17:43:05","modified_gmt":"2024-01-10T12:43:05","slug":"how-to-display-total-views-on-your-wordpress-posts","status":"publish","type":"post","link":"https:\/\/mcstarters.com\/blog\/how-to-display-total-views-on-your-wordpress-posts\/","title":{"rendered":"How to Display Total Views on Your WordPress Posts: A Step-by-Step Guide"},"content":{"rendered":"\n<p>Do you want to display total views on WordPress posts? Here a quick methods to display post views with plugins and without plugins. <\/p>\n\n\n\n<p>Displaying post views on WordPress posts to add value to your services. If you give the product review or any advertisement is a great fit to show the post views. In this way, every visitor sees your traffic and may be impressed to reach out to discuss pricing or details.<\/p>\n\n\n\n<p>You can easily display post views counter up or bottom of the blog post, where you want.<\/p>\n\n\n\n<p>Let&#8217;s get started:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Display Post Views With Plugins<\/h2>\n\n\n\n<p>If you do not know the coding or technical skills, you can display the total views on WordPress posts with plugins.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Post Views Counter <\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1391\" height=\"460\" src=\"https:\/\/mcstarters.com\/blog\/wp-content\/uploads\/2023\/12\/Post-Views-Counter-1.png\" alt=\"Post Views Counter\" class=\"wp-image-30215\" title=\"\" srcset=\"https:\/\/mcstarters.com\/blog\/wp-content\/uploads\/2023\/12\/Post-Views-Counter-1.png 1391w, https:\/\/mcstarters.com\/blog\/wp-content\/uploads\/2023\/12\/Post-Views-Counter-1-768x254.png 768w\" sizes=\"auto, (max-width: 1391px) 100vw, 1391px\" \/><\/figure>\n\n\n\n<p>Post views counter is a compatible and reliable plugin that you use to display post views or visitors. It can pull the data in different ways, what you want to like. Go to the plugin&#8217;s display settings, and customize the style or positions of the view counter. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Page View Count<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1399\" height=\"459\" src=\"https:\/\/mcstarters.com\/blog\/wp-content\/uploads\/2023\/12\/Page-View-Count.png\" alt=\"Page View Count\" class=\"wp-image-30213\" title=\"\" srcset=\"https:\/\/mcstarters.com\/blog\/wp-content\/uploads\/2023\/12\/Page-View-Count.png 1399w, https:\/\/mcstarters.com\/blog\/wp-content\/uploads\/2023\/12\/Page-View-Count-768x252.png 768w\" sizes=\"auto, (max-width: 1399px) 100vw, 1399px\" \/><\/figure>\n\n\n\n<p>Page view count displays the number of page and post views. Go to plugins display settings and change the design of the plugins just show the post views. It can increase the engagement of the users. You can change the color according to color themes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Display Post Views Without Plugins<\/h2>\n\n\n\n<p>You can display the page views with code by making a just few changes in themes.<\/p>\n\n\n\n<p>To add code to your WordPress site for displaying post views, follow these steps:<\/p>\n\n\n\n<p class=\"step\"><strong>Step 1:<\/strong> Log in WordPress admin dashboard.<\/p>\n\n\n\n<p class=\"step\"><strong>Step 2:<\/strong> Go to Appearance, then open Theme Editor.<\/p>\n\n\n\n<p class=\"step\"><strong>Step 3:<\/strong>Open the functions.php file.<\/p>\n\n\n\n<p class=\"step\"><strong>Step 4:<\/strong> Copy and paste the these code before the closing tag ?>:<\/p>\n\n\n\n<pre class=\"wp-block-code bg-code\"><code>function gt_get_post_view() {\r\n    $count = get_post_meta(get_the_ID(), 'post_views_count', true);\r\n    return \"$count views\";\r\n}\r\n\r\nfunction gt_set_post_view() {\r\n    $key = 'post_views_count';\r\n    $post_id = get_the_ID();\r\n    $count = (int) get_post_meta($post_id, $key, true);\r\n    $count++;\r\n    update_post_meta($post_id, $key, $count);\r\n}\r\n\r\nfunction gt_posts_column_views($columns) {\r\n    $columns&#91;'post_views'] = 'Views';\r\n    return $columns;\r\n}\r\n\r\nfunction gt_posts_custom_column_views($column) {\r\n    if ($column === 'post_views') {\r\n        echo gt_get_post_view();\r\n    }\r\n}\r\n\r\nadd_filter('manage_posts_columns', 'gt_posts_column_views');\r\nadd_action('manage_posts_custom_column', 'gt_posts_custom_column_views');\r\n<\/code><\/pre>\n\n\n\n<p class=\"step\"><strong>Step 5:<\/strong> Open the single.php file in the theme editor.<\/p>\n\n\n\n<p class=\"step\"><strong>Step 6:<\/strong> Copy and paste this code in the while loop (use CTRL + F or Command + F to find it in the file): <\/p>\n\n\n\n<pre class=\"wp-block-code bg-code\"><code><code>&lt;?php gt_set_post_view(); ?><\/code><\/code><\/pre>\n\n\n\n<p>This code is responsible for incrementing the views count each time a post is viewed.<\/p>\n\n\n\n<p class=\"step\"><strong>Step 7:<\/strong> Copy and paste this code where you want to display the number of posts or page views: <\/p>\n\n\n\n<pre class=\"wp-block-code bg-code\"><code><code>&lt;?= gt_get_post_view(); ?><\/code><\/code><\/pre>\n\n\n\n<p>This will display the views count on the front end of your site\u200b<a href=\"https:\/\/blog.hubspot.com\/website\/wordpress-post-views\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a>\u200b.<\/p>\n\n\n\n<p>By adding this code to your WordPress site, you will be able to track and display the number of views each post receives, which can be valuable for understanding the popularity and reach of your content.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">WordPress post view count not working<\/h2>\n\n\n\n<p>If your WordPress post view count is not working, there could be several reasons for this issue. Here are some steps you can take to <a href=\"https:\/\/mcstarters.com\/blog\/troubleshooting-fixing-elementor-problems\/\" target=\"_blank\" data-type=\"post\" data-id=\"26337\" rel=\"noreferrer noopener\">troubleshoot and resolve the problem<\/a>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Update the view count plugin and check its settings.<\/li>\n\n\n\n<li>Clear both the website and browser cache.<\/li>\n\n\n\n<li>Temporarily switch to a default WordPress theme.<\/li>\n\n\n\n<li>Check for JavaScript errors in the browser console.<\/li>\n\n\n\n<li>Consult your hosting provider about server-side restrictions.<\/li>\n\n\n\n<li>Ensure WordPress and PHP are up to date.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">conclusion <\/h2>\n\n\n\n<p>In conclusion, displaying total views on WordPress posts involves <a href=\"https:\/\/mcstarters.com\/blog\/adding-custom-fonts-in-elementor-pro\/\" target=\"_blank\" data-type=\"post\" data-id=\"29385\" rel=\"noreferrer noopener\">adding custom<\/a> PHP functions to your WordPress theme. These functions are responsible for tracking the number of times a post is viewed and displaying this count on the front end of your website. <\/p>\n\n\n\n<p>By editing the functions.php file, you introduce a system to increment view counts and retrieve them for display. Additionally, the code can be extended to modify the WordPress admin dashboard, allowing view counts to be visible in the post-management area. This feature enhances the functionality of a WordPress site by providing valuable insights into post popularity and engagement.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do you want to display total views on WordPress posts?&#8230;<\/p>\n","protected":false},"author":2,"featured_media":30224,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[2],"tags":[231,512,520],"class_list":["post-30200","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-wordpress","tag-wordpress-guide","tag-wordpress-posts"],"_links":{"self":[{"href":"https:\/\/mcstarters.com\/blog\/wp-json\/wp\/v2\/posts\/30200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mcstarters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mcstarters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mcstarters.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mcstarters.com\/blog\/wp-json\/wp\/v2\/comments?post=30200"}],"version-history":[{"count":0,"href":"https:\/\/mcstarters.com\/blog\/wp-json\/wp\/v2\/posts\/30200\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mcstarters.com\/blog\/wp-json\/wp\/v2\/media\/30224"}],"wp:attachment":[{"href":"https:\/\/mcstarters.com\/blog\/wp-json\/wp\/v2\/media?parent=30200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mcstarters.com\/blog\/wp-json\/wp\/v2\/categories?post=30200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mcstarters.com\/blog\/wp-json\/wp\/v2\/tags?post=30200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}