How to track pageviews for entries using the [gv_pageviews] shortcode
Have you ever wanted to show how many times an entry has been visited by users?
You can do track the number of visitors to an entry using GravityView's integration with the Pageviews plugin. It's a great visitor counter plugin that now works to track hits to an entry.
When the Pageviews plugin is active, adding the
[gv_pageviews] shortcode to a Single Entry context automatically works with GravityView to track visitors.
To track visitors to an entry:
1. Edit the entry
2. Click the Single Entry tab
3. Add a Custom Content field to your entry
4. Click the gear icon on the newly-added Custom Content field
5. Add this shortcode to the Custom Content field:
6. Update the View
7. Visit your entry and refresh the page!
You'll see a number visible that shows the visit count after refreshing.
Warning: the animated GIF below has flashes as the page reloads.
The shortcode has these attributes:
preload(optional) The preload text, shown while calculating the number of visits. Default:
id(optional) If you want to display Is
What happens when the shortcode is embedded in Multiple Entries?
[gv_pageviews] shortcode is embedded anywhere other than a Single Entry context, the Pageview count will be shown, but not incremented.
Show a different message while the visits count is calculating
To change the preloading message from
..., use the
preload shortcode attribute.
[gv_pageviews preload="Calculating visits…"] will show as this while the calculation is made:
- The shortcode cannot be used outside of the Custom Content field without supplying the
- Cannot sort, order, or filter by pageview (unfortunately!)