Skip to main content
Agency Program Hosting from 10% off. A dedicated account manager. Priority support. Built for growing agencies. Hosting from 10% off, a dedicated account manager and priority support for growing agencies. Speak to the team Join free
WP-PostViews icon

WP-PostViews

v2.0.1
by Lester Chan · 4.4 (65 reviews)

Enables you to display how many times a post/page had been viewed.

90K+ active installs Updated Aug 24, 2026 Tested to 7.1.5 Requires PHP 8.2
Try Demo Download
Pre-installed Ready in ~10s No card
WP-PostViews

About WP-PostViews

This document provides instructions on how to use the WP-PostViews plugin for WordPress. It explains where to place the code to display post views on your website and how to configure the plugin in the WordPress admin panel. It also includes information on the plugin's development, translations, credits, and recent updates.

Screenshots

WP-PostViews screenshot
WP-PostViews screenshot

Frequently asked questions

How do I display post views on my WordPress site?
You can display post views by adding `<?php if(function_exists('the_views')) { the_views(); } ?>` to your theme files like `index.php`, `archive.php`, `single.php`, `post.php`, or `page.php`. Alternatively, use the shortcode `[views]` or `[views id="1"]` within a post.
Where can I configure the WP-PostViews plugin?
The plugin can be configured by navigating to WP-Admin -> Settings -> PostViews in your WordPress dashboard.
What are some of the template variables available in WP-PostViews?
Available template variables include `%POST_CATEGORY_ID%` (which returns the Post's Category ID, or priority Category ID with Yoast SEO) and `%POST_THUMBNAIL%`.
Does the plugin count views in preview mode?
No, the plugin is designed not to count views when a post is in preview mode.
Can I embed view counts directly into a post?
Yes, you can embed view counts into a post using the shortcode `[views]` or `[views id="POST_ID"]`.

Changelog

2.0.1

  • NEW: A Settings link on the plugin’s row on the Plugins screen
  • FIXED: “Count Views From” was only honoured while the page rendered. On a cached site the counting happens through a separate AJAX or REST call instead, and that path never asked the setting — so with “Registered Users Only” a guest hitting a cached page was still counted, and the bot exclusion never applied there either. Both endpoints now check the setting against the actual visitor’s login state

2.0.0

  • FIXED: The two templates are echoed as markup on the strength of being wp_kses_post()‘d when saved — and that was true only of the settings screen. The 2.0.0 migration writes through a different door, and the row it folds in comes from a release that stored the field with no filtering at all, so a hostile template on a site upgrading from 1.78.1 was carried across verbatim and echoed to every visitor. The filtering now happens where the row is written, so WP-CLI, cron, a restored backup and another plugin all pass through it too
  • FIXED: The deferred counting endpoint checked only that an ID named something, and every row in wp_posts answers to that — revisions, autosaves, auto-drafts, attachments, trashed posts, drafts, menu items, reusable blocks. An unauthenticated caller could walk the ID space writing a view row against each one, and read back the count of unpublished posts while doing it. It now requires a real, publicly viewable post, which is what the other counting path already knew
  • FIXED: A view count that is not a number — the meta key is unprefixed, so anyone who can edit a post can type one into Custom Fields — turned every listing containing that post into a fatal error on PHP 8, because both count tokens are built whether or not the template uses them
  • NEW: An editor block, Post Views, under Widgets. It renders on the server through the same code the shortcode uses, so a block and a shortcode showing the same post produce the same markup, and previewing it in the editor never counts a view. The [views] shortcode is unchanged and still supported — nothing needs converting, and posts already containing it keep working.
  • NEW: A wp postviews WP-CLI command — list and get. It reads and never writes.
  • NEW: A postviews/v1 REST API carrying one route, for counting a view from a cached page. Reading a count is already a views field on the core post resource. The admin-ajax.php wp_postviews action is unchanged and still supported.
  • BREAKING: Requires WordPress 6.8 and PHP 8.2.
  • BREAKING: The the_views filter is now wp_postviews_the_views. The template tag the_views() is unchanged.
  • BREAKING: The postviews_should_count filter is now wp_postviews_should_count.
  • BREAKING: The postviews_increment_views and postviews_increment_views_ajax actions are now wp_postviews_increment_views and wp_postviews_increment_views_ajax.
  • BREAKING: The settings are stored in wp_postviews_options instead of views_options, and the upgrade markers in wp_postviews_version instead of views_version. Both are migrated automatically.
  • BREAKING: The WP-Stats toggles move out of the shared stats_display and stats_mostlimit rows into this plugin’s own settings, and the shared rows are deleted. Update all seven WP-Stats plugins together.
  • BREAKING: The widget class WP_Widget_PostViews is now WP_PostViews_Widget. Configured widgets are unaffected.
  • BREAKING: The AJAX action a cached page posts to is now wp_postviews instead of postviews.
  • BREAKING: The six Display Options settings — home page, single posts, pages, archives, searches and other pages — are removed, and the stored keys are dropped on upgrade. Their replacement is the wp_postviews_should_display filter.
  • NEW: Restructured into includes/ classes. The template tags — the_views(), get_most_viewed(), get_least_viewed(), and the category and tag variants — are unchanged and keep working exactly as before.
  • NEW: The options screen is rebuilt on the WordPress Settings API and no longer loads jQuery.
  • NEW: The WP-Stats section, and how many entries its most viewed lists carry, are now settings on Settings -> WP-PostViews.
  • NEW: The wp_postviews_should_display filter decides whether a count is shown. It is read by the_views() only; the [views] shortcode and the admin Views column are explicit requests and ignore it.
  • CHANGED: The settings screen is two tabs, Settings and Templates, over one settings group and one option row.
  • CHANGED: The settings screen is titled “Post Views Settings”, matching the other settings screens in this family.
  • CHANGED: WP-Stats now receives one Views section rather than three separately toggled panels, so the most viewed pages list appears alongside the posts list.
  • FIXED: %VIEW_COUNT_ROUNDED% picked its unit before rounding, so 999,950 displayed as “1000K” instead of “1M” and 999,999,999 as “1000M” instead of “1B”.
  • FIXED: Titles were truncated on bytes rather than characters, because the multibyte branch was gated on MB_OVERLOAD_STRING, which PHP 8.0 removed. A CJK title cut mid-character disappeared from the most/least viewed lists entirely.
  • FIXED: The AJAX endpoint recorded views against post IDs that do not exist, letting anyone add rows to wp_postmeta indefinitely.
  • FIXED: ?v_orderby=ASC was compared against lowercase only, so an uppercase direction — which is what the FAQ tells you to use — silently fell back to descending, the opposite of what was asked for.
  • FIXED: The widget silently discarded changes made in the block widget editor and the customizer, because it required a hidden form field neither of them sends.
  • FIXED: The widget warned about undefined array keys when rendered from the block widget editor or the customizer.
  • FIXED: Uninstalling on a network of more than 100 sites left options and view counts behind on every site after the hundredth, and reported success. Network activation could fatal on the removed wp_get_sites().
  • NOTE: The settings screen moved from options-general.php?page=wp-postviews/postviews-options.php to options-general.php?page=wp-postviews. Update any bookmark; the Settings -> WP-PostViews menu item is where it always was.
  • NOTE: Templates are now stored unslashed. Existing templates are migrated automatically the first time 2.0.0 loads.
  • NOTE: should_views_be_displayed(), postviews_round_number() and snippet_text() are no longer global functions. They were never documented; they are now WP_PostViews_Display::should_be_displayed(), WP_PostViews_Display::round_number() and WP_PostViews_Display::snippet_text().

Try other plugins

Yoast SEO icon

Yoast SEO

4.8 · 10M+ installs

Improve your WordPress SEO: Write better content and have a fully optimized WordPress site using the Yoast SEO…