Init View Count – Lightweight, Accurate, and Developer-Friendly View Counter for WordPress

Version: 1.19.2 Tiếng Việt

Init View Count – Lightweight, Accurate, and Developer-Friendly View Counter for WordPress
Init View Count is a modern WordPress plugin designed to track post views intelligently, accurately, and extensibly. Built with REST API and Vanilla JS, it ensures reliable view counting that avoids bot traffic, prevents duplicate counts, and doesn’t slow down your site. With a clean, bloat-free architecture, this plugin is ideal for blogs, news sites, portfolios, web comics, or any content-focused website that needs real-world post view statistics.

Main Features

  • Track views using REST API + Vanilla JS, excluding bots and crawlers
  • Prevent duplicate counts using sessionStorage or localStorage
  • Supports view counters by: total, day, week, month
  • Auto-insert feature: automatically injects the shortcode before/after post content (per post type)
  • New shortcode attributes: icon="true" and schema="true" for inline icon and Schema.org SEO data
  • class="..." attribute to add custom CSS classes for flexible styling
  • Trending system: calculates rising posts based on hourly view acceleration (via WP-Cron)
  • Stores data in separate meta keys like _init_view_count – no conflict with other plugins/themes
  • Beautiful shortcode templates, fully overrideable from your theme (WooCommerce-style)
  • Fallback thumbnail included for posts without featured image
  • Admin Dashboard widget shows top viewed posts at a glance
  • Built-in Shortcode Builder UI for generating and previewing shortcodes
  • Batch view tracking: store multiple views locally and send in bulk – reduces REST calls
  • Strict IP check: blocks repeated views from the same IP using hashed caching
  • No tracking, no custom tables, no bloat – uses postmeta and transients only

Flexible View Display with Shortcodes

The plugin includes 3 main shortcodes:

  • [init_view_count]: Display the current view count inside a post (supports total/day/week/month, format: raw/formatted/short)
  • [init_view_list]: Show a list of the most viewed posts (customizable post type, category, tag, range, layout, class…)
  • [init_view_list range="trending"]: show currently trending posts based on real-time view spikes
  • [init_view_ranking]: displays a tabbed ranking board (All Time / Today / This Week / This Month), powered by REST API and JavaScript

You can customize number of posts, layout style, filter by category, tag, or post type. Templates can be overridden via your theme to fully match your site’s design. See the documentation: Using the shortcode in Init View Count.

Ready-to-Use REST API

Init View Count provides two REST API endpoints for easy integration with frontend apps or headless WordPress setups:

POST /wp-json/initvico/v1/count

Send a post_id or an array of [post_id1, post_id2, ...] after scroll + delay (supports batch view tracking to update multiple posts at once).

GET /wp-json/initvico/v1/top

Retrieves the most viewed posts. See the documentation: Using the /top REST API in Init View Count.

Supported parameters:

  • range: one of total, day, week, or month (selects the time range for view counts)
  • range=trending: returns posts with the fastest-growing views (trending)
  • post_type: post type to query, defaults to post
  • number: number of posts to retrieve (default: 5)
  • page: which result page to return, used with number for pagination
  • fields: minimal (lightweight) or full (detailed response)
  • tax: taxonomy name (e.g. category, tag, genre)
  • terms: comma-separated term slugs or IDs to filter by
  • no_cache=1: disable caching to always return the latest data

Easy Template Overrides

You can override any display template by adding a file to your theme at:

your-theme/init-view-count/[template-name].php

Example override for a grid layout:

your-theme/init-view-count/view-list-grid.php

Quick Installation

  1. Download and unzip the plugin into /wp-content/plugins/init-view-count/
  2. Activate it via the WordPress admin Plugins menu
  3. Go to Settings → Init View Count to configure options
  4. Use shortcodes in your content or widgets
  5. You can configure Batch view tracking in settings (1 = real-time, >1 = send after batching).

Tabbed Post Ranking by Time Range

Version 1.3 introduces the [init_view_ranking] shortcode — a tabbed UI showing top viewed posts by time (day, week, month, all time).
It uses the REST API under the hood and includes skeleton loading to prevent layout shift during fetch.

Example:

[init_view_ranking tabs="week,month" number="5"]

You can place it on a dedicated /ranking page or anywhere via block, widget, or builder.

Compatibility & Performance

  • Compatible with WordPress 5.5+
  • Requires PHP 7.4 or higher
  • Works with major themes (Astra, Blocksy, Hello…)
  • Uses Vanilla JS, no jQuery dependency

For Developers

Init View Count provides a full set of filters and hooks for maximum flexibility:

  • init_plugin_suite_view_count_should_count: control whether views should be counted for a specific post
  • init_plugin_suite_view_count_meta_key: change the meta key used to store view counts, per post or use case
  • init_plugin_suite_view_count_api_top_args: customize the WP_Query used in the /top API
  • init_plugin_suite_view_count_api_top_item: modify the output of each item in the /top API response
  • init_plugin_suite_view_count_api_top_cache_time: adjust the cache duration for top view results
  • init_plugin_suite_view_count_top_post_types: override the list of post_type used in the /top API
  • init_plugin_suite_view_count_query_args: filter the WP_Query when using the [init_view_list] shortcode
  • init_plugin_suite_view_count_empty_output: customize the HTML output when no posts are found
  • init_plugin_suite_view_count_default_shortcode: change the default shortcode auto-inserted into post content
  • init_plugin_suite_view_count_auto_insert_enabled: enable/disable auto-insert based on post type or context

See the full tutorial: Extending Init View Count with Filters & Hooks.

Get Started

Need a lightweight, precise, and extensible post view counter for WordPress? Init View Count is your ultimate solution.

Review

5.0/5 (2)

Changelog

  • 1.19 – Hotfix: Enable Day/Week/Month Counters by Default
    • Default enabled counters:
      • init_plugin_suite_view_count_enable_day → default = 1
      • init_plugin_suite_view_count_enable_week → default = 1
      • init_plugin_suite_view_count_enable_month → default = 1
    • Bug fix: Previously, if the user did not save the settings page, the counters would remain disabled and views were not counted.
    • Backward compatibility:
      • If options were already saved, the plugin still respects the saved values.
      • No migration required – hotfix applies automatically to all sites.
  • 1.18 – History storage & disable Trending option
    • History Storage (Archive Keys):
      • On reset, previous values are archived into new meta keys:
        _init_view_yesterday, _init_view_last_week, _init_view_last_month.
      • Useful for reviewing yesterday’s, last week’s, or last month’s data directly.
      • Completely safe, does not affect the existing reset logic.
    • Option to disable Trending Engine:
      • New filter init_view_count_trending_enabled – allows disabling the entire trending engine if not needed.
      • When disabled, all cron jobs and trending calculations are skipped, while view count features continue normally.
      • Backward compatible: trending remains enabled by default.
    • Ranking Shortcode:
      • Extended [init_view_ranking] to support new tabs:
        yesterday, last_week, last_month.
      • Default tabs unchanged (total,day,week,month).
      • JS & REST API enhancements for new tabs will be rolled out gradually.
    • REST API Top:
      • Extended /top endpoint with support for
        range=yesterday|last_week|last_month.
      • Results are consistent with reset logic and new archive keys.
    • Backward compatibility: All existing features (day/week/month/total/trending) remain intact to ensure zero breakage for existing sites.
  • 1.17 – Traffic Shape Learner + Trending Engine improvements
    • Introduced Traffic Shape Learner – AI-powered hourly & weekday distribution model:
      • Collects raw hourly bins and rolls them up into site-wide traffic shape.
      • Hour-of-day pattern updated via EMA + Bayesian prior smoothing (kappa control).
      • Day-of-week pattern updated via EMA with stabilized daily totals.
      • Both distributions normalized to mean = 1 for consistent multiplicative scaling.
    • Performance & caching:
      • Learned shapes cached in transient for 2h (filterable TTL).
      • Rollup action protected by object-cache lock to prevent race conditions.
      • Minimal overhead: only 1 write per view increment + 1 rollup per day.
    • Filters & extensibility:
      • init_plugin_suite_view_count_site_traffic_shape – provides current hour/day shape arrays.
      • Tunable alpha/kappa values via filters for both models.
      • init_plugin_suite_view_count_shape_collect_enabled – enable/disable collection.
    • Reset & admin:
      • New admin-post action init_plugin_suite_view_count_shape_reset to clear all learned shape data.
      • Safe to run anytime – plugin will automatically rebuild patterns.
    • Trending Engine improvements:
      • Multi-key fallback (day → week → month → total) ensures enough posts even at early hours.
      • Day-views fallback estimation from week/month averages prevents empty scores.
      • Optimized CRON queries: skip week/month/total lookups if daily data already sufficient.
      • Debug payload now includes views_day_used and fallback flags.
    • Backward compatibility: all existing view count & trending filters remain intact. Trending Engine v3 (1.16) automatically integrates with learned shapes for uplift calculation.
  • 1.16 – Trending Engine v3 + AI-powered enhancements
    • Upgraded to Trending Engine v3 – introducing AI-powered uplift and multi-layered scoring:
      • Added uplift scoring based on expected traffic patterns (hourly/daily) to adjust scores dynamically.
      • Introduced EWMA momentum with acceleration for smoother and more stable trend detection.
      • Implemented anti-gaming checks to cap score growth per cron run.
      • Added exposure fatigue to reduce dominance of posts staying at the top too long.
    • Integrated MMR re-ranking to improve diversity across categories/tags.
    • Introduced explore/exploit logic to occasionally boost promising new posts.
    • Extended debug payload in REST API:
      • New fields include: uplift_raw, expected_views, ewma_val, acc, fatigue_streak.
  • 1.15 – Trending Engine v2 + Performance Optimization
    • Upgraded Trending Engine v2 – optimized for performance and stability:
      • Added cache lock (object cache) to prevent race conditions when cron overlaps.
      • Implemented soft-cap exponential formula for smooth limits, avoiding hard caps.
      • Optimized O(n) diversity filter with auto fill-back to always return enough results.
      • Improved hot topics SQL for ONLY_FULL_GROUP_BY compatibility and timezone safety with post_date_gmt.
      • Reduced N+1 queries by caching author_id, categories, and tags per post.
    • New filters for Trending:
      • init_plugin_suite_view_count_trending_post_types – limit/override post types (e.g., only manga).
      • init_plugin_suite_view_count_trending_component_weights – adjust weights for Velocity, Engagement, Freshness, Momentum.
    • Sanitization & fallback: normalized post types from settings, auto-removed attachment, safe fallback when empty.
    • Engagement smoothing – improved stability when daily views are low.
  • 1.14 – Hybrid trending algorithm with diversity filter
    • Introduced a powerful Hybrid Trending Algorithm that scores posts based on multiple dynamic factors.
    • Trending scores are updated hourly and combine five key components:
      • Velocity: view growth rate per hour, with logarithmic scaling to prevent high-view bias.
      • Time Decay: score decays naturally over time with a 36-hour half-life curve.
      • Engagement: quality of interactions (comments, likes, shares) per view.
      • Freshness: boost for newer content published within the last 24 hours.
      • Momentum: score boost for content related to hot categories or tags in the past 24 hours.
    • Trending results are cached using transient and automatically refreshed via WP-Cron every hour.
    • Added a Diversity Filter to ensure balanced results across authors and categories:
      • Limits to 2 posts per author and 3 posts per category (only if there are enough unique items).
      • Limits are automatically relaxed if there aren’t enough authors or categories to fill the list.
    • Fully compatible with all public post types, taxonomies, and existing view tracking logic.
  • 1.13 – Top View API Post Type Filter
    • Added the init_plugin_suite_view_count_top_post_types filter to customize the post_type list used in the /top API endpoint.
    • Fully backward-compatible: defaults to ['post', 'page'] if no filter is applied.
    • Useful for limiting results to specific content types such as manga, article, etc.
  • 1.12 – Support view count for any post ID
    • The [init_view_count] shortcode now supports an id="..." attribute to display the view count of any post, not just the current one.
    • Fully backward-compatible: if id is not provided, the current post ID will be used by default.
    • Useful for showing view counts of related posts, featured posts, or custom layouts.
  • 1.11 – Post type filtering + time display cleanup
    • Shortcode [init_view_ranking] now supports post_type="..." to filter results by custom post type (e.g. post, page, manga…).
    • Updated ranking.js to pass post_type to the REST API and cache results per tab and post type.
    • Removed the custom function init_plugin_suite_view_count_human_time_diff() in favor of WordPress core human_time_diff().
    • The [init_view_count] shortcode now uses human_time_diff() for displaying publish time (when time="true" is enabled).
    • All templates have been updated to use the native human_time_diff() function.
  • 1.10 – Auto insert, schema.org, and custom class support
    • Added new “Auto-insert shortcode” setting – automatically injects [init_view_count] before or after post content.
    • Auto-insert only applies to post types with tracking enabled – fully toggleable or filterable per context.
    • New shortcode attribute icon="true" to show a small inline SVG icon before the view count in [init_view_count].
    • New attribute schema="true" to output InteractionCounter Schema.org microdata for better SEO.
    • New class="..." attribute to allow adding custom CSS classes to the shortcode wrapper.
    • Added two new filters:
      • init_plugin_suite_view_count_default_shortcode – customize the default auto-inserted shortcode output.
      • init_plugin_suite_view_count_auto_insert_enabled – enable/disable auto insert by post type or position.
    • Fully backward-compatible – all new features are optional and disabled by default.
  • 1.9 – PHP 7.4 Compatibility
    • Replaced all PHP 8 match expressions with array maps and switch statements for PHP 7.4 compatibility.
    • No changes to logic – all filters like init_plugin_suite_view_count_meta_key remain fully functional.
    • Applies to all REST API endpoints and shortcodes: [init_view_count], [init_view_list], etc.
    • This is not a feature update – just a syntax downgrade to prevent fatal errors on outdated servers.
  • 1.8 – Block Fake Views via Strict IP Check
    • Added Strict IP check option to block repeated views from the same IP within a short period.
    • Uses hashed IPs and a FIFO-style transient cache (default: 75 recent IPs per post).
    • Prevents bots or scripts from sending fake views directly via the REST API (e.g., cURL or cron jobs).
    • Privacy-safe: raw IPs are never stored and entries expire automatically over time.
    • New setting: “Enable strict IP check?” – disabled by default for compatibility.
  • 1.7 – Ranking Widget & API Limit Handling
    • Added a Dashboard Widget that displays most viewed posts using the [init_view_ranking] shortcode.
    • Introduced a minimal admin-style.css file to ensure clean, single-line widget display.
    • Improved REST API /count to respect the configured batch limit and prevent server overload.
    • Performed minor backend cleanup and standardized hook structure for future updates.
  • 1.6 – Batch View Tracking
    • Added new Batch view tracking option – allows grouping multiple views before sending to the server.
    • Batch threshold is configurable in plugin settings (default is 1 – real-time tracking as before).
    • Views are temporarily stored in localStorage and only sent when the threshold is met.
    • Greatly reduces REST requests on high-traffic sites while maintaining accuracy.
    • Refactored script.js to support scroll + delay + batch logic in a clean structure.
    • REST API /count now accepts an array of post_id values instead of just one.
    • View count is updated instantly in the UI after tracking (no reload required).
  • 1.5 – Shortcode Builder UI
    • Added a visual shortcode builder panel in the plugin settings page.
    • Supports generating [init_view_count], [init_view_list], and [init_view_ranking] with all available attributes.
    • New script init-shortcode-builder.js is isolated and only loads where needed.
    • All UI strings are localized via InitViewCountShortcodeBuilder.i18n for full translation support.
    • JS architecture is now modular: core logic and UI are separated for future extensibility.
  • 1.4 – Trending algorithm and hourly view analysis
    • Introduced the Trending scoring system based on views per hour and post age.
    • Trending scores are updated hourly via WP-Cron, optimized for large, high-traffic sites.
    • The /top REST API now supports range=trending with built-in sorting and pagination.
    • The [init_view_list range="trending"] shortcode displays currently trending posts.
    • Also added /trending slash command support (used via Init Live Search plugin).
    • All trending logic respects internal meta_key filters for advanced customization.
    • Improved post meta cleanup logic for day/week/month resets using filterable meta keys.
  • 1.3 – New shortcode for tabbed post ranking by time range
    • Added [init_view_ranking] shortcode to display a tabbed interface showing top posts by today / week / month / all time.
    • Uses REST API + lazy-loading via JavaScript, only loads when visible — perfect for SPA/headless environments.
    • Includes built-in skeleton loader to maintain layout consistency during loading.
    • Follows consistent CSS naming using init-plugin-suite-view-count-* class prefix for easy theming and extension.
    • JavaScript is conditionally enqueued only when the shortcode is present on the page.
  • 1.2 – CSS Optimization and Advanced Meta Key Support
    • style.css is now enqueued earlier to avoid being loaded in the footer.
    • Added an option in the settings page to disable the plugin’s default CSS.
    • The init_plugin_suite_view_count_meta_key filter is now applied consistently across REST API, shortcode, and WP-Cron.
    • Fixed an issue where custom meta key overrides were ignored in some cases.
  • 1.1 – Pagination Support for View Lists
    • Added page parameter to the /top REST API endpoint to support pagination.
    • The [init_view_list] shortcode now supports the page attribute to display a specific result page.
  • 1.0 – Initial Release of Init View Count
    • Counts post views using REST API + Vanilla JS, avoids bots and duplicate hits via session/localStorage.
    • Stores view counts in a dedicated meta key _init_view_count to avoid conflicts with themes or other plugins.
    • Supports daily, weekly, monthly, and total counts with automatic reset via WP-Cron.
    • [init_view_count] shortcode displays the view count with support for raw/formatted/short formats and post date difference.
    • [init_view_list] shortcode displays most viewed posts with full control over number, post type, range, category, tag, template, class, etc.
    • Supports template override from themes using the structure your-theme/init-view-count/*.php, similar to WooCommerce.
    • REST API GET /wp-json/initvico/v1/top supports filtering by any taxonomy (category, tag, genre…), caching, and fields=minimal|full mode.
    • REST API POST /wp-json/initvico/v1/count records accurate views for individual posts.
    • Includes a powerful system of filters and action hooks for developers: control when views count, override meta key, customize query, API output, cache time, and more.
    • No custom tables, no tracking, no bloat – uses only postmeta, lightweight and extendable.
Made with in HCMC.

Comments


  • No comments yet.

Init Toolbox

Press Ctrl + \ on desktop, or swipe left anywhere on mobile.

Login