Init View Count – Accurate Post Views with REST API & Custom Shortcodes

A fast, minimalist view counter for WordPress – REST-first and developer-friendly

Init View Count tracks post views using JavaScript + REST API for precision and flexibility. It includes shortcodes, tabbed rankings, template overrides, and w…


This content originally appeared on DEV Community and was authored by Hao Nguyen

A fast, minimalist view counter for WordPress – REST-first and developer-friendly

Init View Count tracks post views using JavaScript + REST API for precision and flexibility. It includes shortcodes, tabbed rankings, template overrides, and works with any post type.

No jQuery. No cookies. No fluff.

Features at a Glance

Lightweight and Accurate

  • Tracks views via REST API + scroll + delay logic
  • Prevents duplicates with session/localStorage
  • Optional batch mode: queue views and send in groups
  • Optional strict IP-based filtering (no raw IP storage)

Flexible Shortcodes

  • [init_view_count] – show current post view count
  • [init_view_list] – show list of most viewed posts
  • [init_view_ranking] – tabbed ranking by day/week/month/total
  • Fully theme-overridable templates (your-theme/init-view-count/*.php)
  • Format options: raw, formatted, short number, schema.org support

Clean Admin Tools

  • Dashboard widget to show top viewed posts
  • Settings panel to enable post types, batch, delay, scroll, etc.
  • Shortcode builders for all views with live preview

Minimal Overhead

  • No assets loaded unless shortcode used
  • CSS can be disabled completely
  • No tracking, no analytics bloat

Built for Developers

  • Custom meta key support via filters
  • Exposed REST API endpoints for tracking + top posts
  • Fully filterable output and query logic
  • Compatible with headless setups and SPAs

REST API Endpoints

POST /wp-json/initvico/v1/count

Record one or more post views.

Parameters:

  • post_id (int|array): One or more post IDs

GET /wp-json/initvico/v1/top

Retrieve top posts by views.

Parameters include:

  • range: total, day, week, month, trending
  • number: Number of posts
  • post_type, category, tag, etc.
  • fields: minimal or full
  • no_cache: Disable transient caching

👉 Full REST Guide

Shortcode Examples

Shortcode Description
[init_view_count] Show view count for current post
[init_view_list] Most viewed posts list
[init_view_ranking] Tabbed list by day/week/month/total

Add template, range, icon, schema, class, field, and other options as needed.

👉 Full Shortcode Guide

Dev Tools You Get

  • Filters like init_plugin_suite_view_count_should_count, *_meta_key, *_top_args
  • Modify output of /top API with init_plugin_suite_view_count_api_top_item
  • Theme override with view-list-sidebar.php, view-list-grid.php, etc.
  • Zero jQuery. Zero cookies. Fully modular JS.

Installation

Install via WordPress.org or:

git clone https://github.com/brokensmile2103/init-view-count.git

Then activate and configure in Settings → Init View Count.

Ways to show views:

  • Add [init_view_count] in post content
  • Use auto-insert (before/after post content)
  • Place view lists with [init_view_list]
  • Show trending or ranked tabs with [init_view_ranking]

Part of the Init Plugin Suite

Init View Count is part of the Init Plugin Suite – a set of minimalist, performance-first tools for WordPress developers.

Thanks for reading. Got feedback or ideas?

Project Page

GitHub


This content originally appeared on DEV Community and was authored by Hao Nguyen


Print Share Comment Cite Upload Translate Updates
APA

Hao Nguyen | Sciencx (2025-06-26T16:11:18+00:00) Init View Count – Accurate Post Views with REST API & Custom Shortcodes. Retrieved from https://www.scien.cx/2025/06/26/init-view-count-accurate-post-views-with-rest-api-custom-shortcodes/

MLA
" » Init View Count – Accurate Post Views with REST API & Custom Shortcodes." Hao Nguyen | Sciencx - Thursday June 26, 2025, https://www.scien.cx/2025/06/26/init-view-count-accurate-post-views-with-rest-api-custom-shortcodes/
HARVARD
Hao Nguyen | Sciencx Thursday June 26, 2025 » Init View Count – Accurate Post Views with REST API & Custom Shortcodes., viewed ,<https://www.scien.cx/2025/06/26/init-view-count-accurate-post-views-with-rest-api-custom-shortcodes/>
VANCOUVER
Hao Nguyen | Sciencx - » Init View Count – Accurate Post Views with REST API & Custom Shortcodes. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/06/26/init-view-count-accurate-post-views-with-rest-api-custom-shortcodes/
CHICAGO
" » Init View Count – Accurate Post Views with REST API & Custom Shortcodes." Hao Nguyen | Sciencx - Accessed . https://www.scien.cx/2025/06/26/init-view-count-accurate-post-views-with-rest-api-custom-shortcodes/
IEEE
" » Init View Count – Accurate Post Views with REST API & Custom Shortcodes." Hao Nguyen | Sciencx [Online]. Available: https://www.scien.cx/2025/06/26/init-view-count-accurate-post-views-with-rest-api-custom-shortcodes/. [Accessed: ]
rf:citation
» Init View Count – Accurate Post Views with REST API & Custom Shortcodes | Hao Nguyen | Sciencx | https://www.scien.cx/2025/06/26/init-view-count-accurate-post-views-with-rest-api-custom-shortcodes/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.