Page View Count Shortcode

Below, you’ll find a detailed guide on how to add the Page View Count Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Page View Count Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Page View Count Plugin and the shortcodes it provides:

Plugin Icon
Page View Count

"Page View Count is a dynamic WordPress plugin that enables users to monitor and display the number of views for each page. Its simple, user-friendly design makes tracking site engagement easier."

★★★☆✩ (51) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [pvc_stats]

Page View Count [pvc_stats] Shortcode

The ‘pvc_stats’ shortcode from the Page-Views-Count plugin is used to display page view statistics. This shortcode allows you to input a ‘postid’, ‘increase’ and ‘show_views_today’ attributes. The ‘postid’ attribute is used to specify the post ID. The ‘increase’ attribute is used to increment the view count, while ‘show_views_today’ lets you display the number of views for the current day.

Shortcode: [pvc_stats]

Parameters

Here is a list of all possible pvc_stats shortcode parameters and attributes:

  • postid – Identifies the specific post to track views for.
  • increase – Controls the increment of the view count, default is 1.
  • show_views_today – If set to 1, it shows today’s views. 0 hides them.

Examples and Usage

Basic example – A simple usage of the ‘pvc_stats’ shortcode to display the page view count of a specific post. The ‘postid’ attribute is used to specify the ID of the post.

[pvc_stats postid=45 /]

Advanced examples

Using the ‘pvc_stats’ shortcode with multiple attributes. In this example, the ‘postid’ attribute specifies the post, the ‘increase’ attribute is set to 0 to prevent the view count from increasing when the page is viewed, and the ‘show_views_today’ attribute is set to 0 to hide the count of views for the current day.

[pvc_stats postid=45 increase=0 show_views_today=0 /]

Another advanced usage of the ‘pvc_stats’ shortcode. In this example, the ‘postid’ attribute specifies the post, and the ‘increase’ attribute is set to 1 to increase the view count each time the page is viewed. The ‘show_views_today’ attribute is not included, so it will default to 1, showing the count of views for the current day.

[pvc_stats postid=45 increase=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [pvc_stats] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'pvc_stats', array( $this, 'parse_shortcode') );

Shortcode PHP function:

function parse_shortcode( $attr = array() ) {
		if ( is_admin() ) {
			return '';
		}

		$attr = shortcode_atts(
			array(
				'postid'           => '',
				'increase'         => 1,
				'show_views_today' => 1,
			), $attr );

		$postid           = esc_attr( $attr['postid'] );
		$increase         = intval( $attr['increase'] );
		$show_views_today = intval( $attr['show_views_today'] );

		$output = apply_filters( 'pvc_stats_shortcode', '', $postid, $increase, $show_views_today );

		return $output;
	}

Code file location:

page-views-count/page-views-count/src/pvc_shortcode.php

Conclusion

Now that you’ve learned how to embed the Page View Count Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *