3. Manual Usage
The Post Views Counter plugin allows users to automatically display the counter on pages and/or posts. However, if they’d like to add the counter to only a few selected pages/posts or on different areas of the page/post then they can do so manually.
3.1 Display views with a shortcode
The Post Views Counter plugin allows users to automatically display the counter on pages and/or posts. However, if they’d like to add the counter to only a few selected pages/posts or on different areas of the page/post then they can do so manually using the [post-views] shortcode.
To use this shortcode, head over to the page or post you wish to embed the post views counter on. In its text editor, enter the [post-views] shortcode where you want the counter to be displayed.
Click the Save Draft button to continue. When you preview the post or page, it should look something like the image above.
The shortcode also provides an optional id parameter which may be used to show post views for any specified post anywhere on the page. For example [post-views id="42"] would display post views for the post of id equal to 42.
To use this, find the id of the post you wish to embed the count of. Head over to the page or post where you want to embed this post’s counter. In its text editor, enter the [post-views id="42"] shortcode where you want the counter to be displayed.
Click the Save Draft button to continue. It should look something like this:
3.2 Display views with a function
Description
Displays a post’s total post views along with the label and/or icon. The function is located in the functions.php file of the plugin.
Usage
pvc_post_views( $post_id = 0, $echo = true );
Parameters
- $post_id | int: Stores the post’s ID.
- $echo | boolean: Determines whether the post views should be displayed or returned.
Return
A string of display options that include the post’s ID, total number of views, label, and icon.
3.3 Count views with a function
(via pvc_view_post() function also located in functions.php plugin file
Description
Allows the user to view a given post manually. The function is located in the functions.php file of the plugin.
Usage
pvc_view_post( $post_id = 0 );
Parameters
- $post_id | int: Stores the post’s ID.
Return
FALSE if the post doesn’t exist; TRUE if the post exists.
12 comments on "Manual Usage"
Maria Fonseca says:
3 April 2018 at 09:20
Hi!
Is there a way to display the views of all posts, that is, the total views of the website?
Thank you!
Maria
Kamruzzaman Emon says:
5 March 2018 at 09:35
I want this plugin count in my theme. So I need the plugin meta code. what is that?
Bartosz Arendt says:
7 March 2018 at 15:07
The plugin is not storing data in post meta. But you have the above functions to do that.
Henrik says:
18 February 2018 at 16:30
Hi
Great plugin.
I want to add the view counter in the section just under the post-title. The section with the post-date, post-author and categories. But it’s a little tricky for me.
It works on the post’s page. But in the frontpage where I have a list of recent posts, it shows down in front of the text and not up with the post-date, post-author and categories. Why is that ?
Bartosz Arendt says:
7 March 2018 at 15:09
The code is displayed using a WP native action hooks (like the_content). The place where these are tirggered is controlled by your theme.
Dmutiy says:
7 February 2018 at 16:23
Hi!
Tell me how to get the counter not only inside the post?
For example on the page next to each news.
Sumeet Kalsey says:
23 November 2017 at 07:40
I want to apply this in my theme what is the shortcode
I used all mentioned above Please tell me the shortcode
See the screenshot
Website is https://www.newsview.in
Bartosz Arendt says:
23 November 2017 at 09:17
It’s [post-views id="42"] as described above.
hello says:
12 November 2017 at 19:06
Thank you!
How can I change the number of views?
Bartosz Arendt says:
14 November 2017 at 14:49
What do you mean? You have an option for that for each post separatelly.
Caner says:
8 November 2017 at 20:59
Thank you for this great plug-in.
Is there a way to hide the counter on spesific pages or posts? I want to hide it on some pages and posts because of their purposes.
Regars
Bartosz Arendt says:
9 November 2017 at 13:12
Yep, here you’ll find an example https://dfactory.eu/support/topic/how-to-hide-plugin-on-older-posts/