Post Views Counter
Track how many times your posts are viewed and display view counts on the frontend. Identify your most popular content and understand what resonates with your audience.
Use Cases
- Identify which posts attract the most visitors
- Display view counts to show content popularity (social proof)
- Make data-driven decisions about content strategy
- Find trending topics to create more similar content
- Track content performance over time
How It Works
- When a visitor views a post, the count increments
- View counts are stored in the database per post
- A “Views” column appears in your posts list
- Use the shortcode to display counts on the frontend
- Sort posts by views to find your most popular content
Where to Find It
Locations:
- Admin: Posts → All Posts (Views column)
- Frontend: Use
[post_views]shortcode
What Gets Tracked
| Visitor Type | Tracked? | Notes |
|---|---|---|
| Anonymous visitors | Yes | Main audience tracking |
| Logged-in users | No | Excludes admins/editors |
| Bots (if they run JS) | No | Most bots don’t count |
| Your own visits | No | You’re logged in |
By default, only anonymous visitors are counted. This gives you clean data about actual reader engagement without inflating numbers with your own editing visits.
Admin Views Column
In Posts → All Posts, you’ll see a “Views” column showing:
- The view count for each post
- Click the column header to sort by views
- Quickly identify your most and least popular content
Sorting by Views
Click the “Views” column header to sort:
- Ascending: Find posts that need more promotion
- Descending: See your top performers
Frontend Display
Use the shortcode to show view counts on your site:
[post_views]Output: 1,234 views
Placement Ideas
Add the shortcode in:
- Post templates (under the title)
- After post content
- In widget areas
- Custom template files
In Theme Templates
<?php echo do_shortcode('[post_views]'); ?>
Popular Placement Example
Under your post title:
<div class="post-meta">
<span class="post-date"><?php echo get_the_date(); ?></span>
<span class="post-views"><?php echo do_shortcode('[post_views]'); ?></span>
</div>Styling
The view count displays as plain text with the format “X,XXX views”. Style it with CSS by wrapping in a custom class:
<span class="view-count"><?php echo do_shortcode('[post_views]'); ?></span>.view-count {
color: #666;
font-size: 14px;
}
.view-count::before {
content: "👁 ";
}Creating Popular Posts Lists
While the module doesn’t include a widget, you can create a popular posts list using a custom query:
<?php
$popular_posts = new WP_Query([
'post_type' => 'post',
'posts_per_page' => 5,
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC'
]);
if ($popular_posts->have_posts()) :
echo '<ul class="popular-posts">';
while ($popular_posts->have_posts()) : $popular_posts->the_post();
$views = get_post_meta(get_the_ID(), 'post_views_count', true);
echo '<li>';
echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
echo ' <span>(' . number_format($views) . ' views)</span>';
echo '</li>';
endwhile;
echo '</ul>';
wp_reset_postdata();
endif;
?>
Data Storage
View counts are stored as post meta with the key post_views_count. This means:
- Data persists even if you deactivate the module
- You can query posts by view count
- Counts are exportable with your posts
- No separate database tables
FAQ
Why aren’t my views counting?
Make sure you’re testing as a logged-out visitor. By default, logged-in users don’t increment the counter. Try an incognito window or log out to test.Can I reset view counts?
Yes, edit the post and look for thepost_views_count custom field, or delete it via a database query. You can also set it to a specific number.Are cached pages counted?
If using page caching, views may only count when the cache is bypassed. For accurate counts with heavy caching, consider a JavaScript-based counter instead.Does this work with custom post types?
Yes, the counter automatically tracks views on all single post pages including custom post types. It works with posts, products, portfolio items, and any other custom post type.Can I count logged-in users too?
The default behavior excludes logged-in users to keep counts focused on your actual audience. This would require code modification to change.Use view counts along with time published to calculate trending content. A post with 1,000 views in one week is trending hotter than one with 1,000 views over a year.
This is a simple view counter, not a full analytics solution. For detailed analytics including time on page, bounce rate, and traffic sources, use Google Analytics or a similar service.
Get access to all 147 modules with a single license