Docs / Configuration / Display Options

Display Options

Shortcodes, Gutenberg block, PHP template function, and automatic placement.

Automatic Placement

In View Counter → Settings → Display & Admin UI, set Auto Display to Before content or After content. View Counter will then add the view count automatically on enabled post types.

Shortcode

Use [view_counter] anywhere shortcodes are supported:

[view_counter]
[view_counter post_id="142"]
[view_counter label="Total reads" format="{label}: {count}"]

Compatibility aliases are also available:

[view-counter]
[viewcounter]

Attributes:

  • post_id — specific post ID. Defaults to the current post.
  • label — override the label text.
  • format — override the format template.
  • before — HTML/text to output before the view count markup.
  • after — HTML/text to output after the view count markup.
  • class — extra CSS class added to the count span.

Gutenberg Block

Search for ViewCounter in the block inserter. The block displays the tracked view count for the current post, or for a specific post ID if one is entered.

The block includes optional controls for Post ID, Label, and Format. If left blank, it uses your global display settings.

PHP Template Function

For theme developers, use vc_get_post_views() in your templates:

<span class="post-views">
    <?php echo number_format_i18n( vc_get_post_views() ); ?> views
</span>

Or for a specific post: echo vc_get_post_views( 142 );

vc_get_post_views() returns a raw integer, so theme templates should format or label it as needed.

Tip

The shortcode and block use your global label and format settings unless you pass their own label or format. The PHP function returns only the raw count.