Skip to main content

Shortcodes

Burst Statistics provides shortcodes to display analytics data on the frontend of your WordPress site.

[burst_statistics]

The main shortcode for displaying statistics. Supports multiple display types, date ranges, and output formats.

Basic usage:

[burst_statistics type="pageviews"]

Parameters

ParameterTypeDefaultDescription
typestringpageviewsThe type of statistic to display. See Supported Types below.
periodstring30daysPredefined date period. Used when start_date/end_date are not set.
post_idstring(empty)Numeric post ID to filter stats for a specific post, or current to use the current post.
page_urlstring(empty)Relative URL path to filter stats for a specific page. Takes precedence over post_id.
object_typestringpostObject type context for the query.
limitint5Maximum number of items for list-type results (top_pages, top_referrers, device_breakdown, most_visited).
formatstringnumberOutput format for single-value types. number renders the raw formatted number; text renders a label with the value.
labelstring(empty)Optional custom label rendered above the statistic value.
empty_messagestring(empty)Message to display when no data is found.
cache_durationint3600Transient cache duration in seconds. Set to 0 to disable caching.
start_datestring(empty)Start of a custom date range. Format: YYYY-MM-DD.
end_datestring(empty)End of a custom date range. Format: YYYY-MM-DD.
show_countboolfalseWhether to display the view count next to each item. Only applies to most_visited type.
post_typestringpostWordPress post type to filter. Only applies to most_visited type. Must be a public post type.

Supported Types

Single-value types

These types render a single formatted number or text value.

type valueDescription
pageviewsTotal number of page views.
visitorsTotal number of unique visitors.
sessionsTotal number of sessions.
bounce_rateBounce rate as a percentage (e.g. 42.3%).
avg_time_on_pageAverage time on page, formatted as seconds (e.g. 34 seconds).
first_time_visitorsNumber of first-time visitors.
conversionsTotal number of conversions.

List types

These types render a <ul> list of items.

type valueDescription
top_pagesMost visited pages, showing page title and view count.
top_referrersTop referral sources, showing referrer domain and view count.
device_breakdownBreakdown of visits by device type (Desktop, Tablet, Mobile, Other), showing percentage share.
most_visitedMost visited posts. Supports post_type and show_count parameters.

Examples

Total pageviews for the last 30 days:

[burst_statistics type="pageviews"]

Visitors for the current post:

[burst_statistics type="visitors" post_id="current"]

Pageviews for a specific post:

[burst_statistics type="pageviews" post_id="42"]

Pageviews for a specific URL path:

[burst_statistics type="pageviews" page_url="/about/"]

Bounce rate with a custom label:

[burst_statistics type="bounce_rate" label="Bounce rate (last 30 days)"]

Pageviews in text format (shows metric name + value):

[burst_statistics type="pageviews" format="text"]

Custom date range:

[burst_statistics type="pageviews" start_date="2024-01-01" end_date="2024-01-31"]

Top 10 pages with a fallback message:

[burst_statistics type="top_pages" limit="10" empty_message="No data available yet."]

Top referrers:

[burst_statistics type="top_referrers" limit="5"]

Device breakdown:

[burst_statistics type="device_breakdown"]

Most visited posts (post type: page, show view count):

[burst_statistics type="most_visited" post_type="page" limit="5" show_count="true"]

Disable caching:

[burst_statistics type="pageviews" cache_duration="0"]

Output HTML

Single-value types render a <p> tag with type-specific CSS classes:

<!-- format="number" (default) -->
<p class="burst-statistics-number burst-statistics-pageviews">1,234</p>

<!-- format="text" -->
<p class="burst-statistics-text burst-statistics-pageviews">Page Views: 1,234</p>

<!-- With label="My label" -->
<p class="burst-statistics-custom-label">My label</p>
<p class="burst-statistics-number burst-statistics-pageviews">1,234</p>

List types render a <ul> with class burst-statistics-list and a type-specific modifier class:

<ul class="burst-statistics-list burst-statistics-top_pages">
<li class="burst-statistics-item">
<span class="burst-statistics-label">Homepage</span>
<span class="burst-statistics-value">5,678</span>
</li>
...
</ul>

When no results are found and empty_message is set:

<p class="burst-statistics-empty">No data available yet.</p>

[burst-most-visited] (deprecated)

caution

This shortcode was deprecated in version 1.5.0. Use [burst_statistics type="most_visited"] instead. The shortcode remains registered for backward compatibility but will trigger a deprecation notice in the WordPress admin for users with manage_options capability.

Old usage:

[burst-most-visited count="5" post_type="post" show_count="false"]

Equivalent new usage:

[burst_statistics type="most_visited" limit="5" post_type="post" show_count="false"]

Parameter mapping

Old parameterNew parameterNotes
countlimitNumber of posts to display.
post_typepost_typeWordPress post type.
show_countshow_countWhether to display the view count.

Filters and Hooks

burst_statistics_shortcode_custom_type

Allows registering a custom type value not handled by the built-in switch. Return an HTML string to use as the shortcode output; return false to fall through to the default invalid-type error.

Parameters:

ParameterTypeDescription
$outputfalseAlways false on input; return an HTML string to provide custom output.
$attsarrayFull sanitized shortcode attributes.
$startstringResolved query start date.
$endstringResolved query end date.

Example:

add_filter( 'burst_statistics_shortcode_custom_type', function( $output, $atts, $start, $end ) {
if ( $atts['type'] !== 'my_custom_stat' ) {
return $output; // Return false to let Burst handle it.
}

// Build and return your own HTML output.
return '<p>My custom stat output</p>';
}, 10, 4 );

burst_statistics_shortcode_query_args

Allows modifying the query arguments before the database query is executed. Use this to adjust select, filters, group_by, order_by, or limit for any built-in type.

Parameters:

ParameterTypeDescription
$query_argsarrayArray with keys select, filters, group_by, order_by, limit.
$attsarrayFull sanitized shortcode attributes.

Example:

add_filter( 'burst_statistics_shortcode_query_args', function( $query_args, $atts ) {
// Cap the limit for top_pages to 3.
if ( $atts['type'] === 'top_pages' ) {
$query_args['limit'] = min( $query_args['limit'], 3 );
}

return $query_args;
}, 10, 2 );

burst_statistics_shortcode_output

Allows modifying the final HTML output of the shortcode before it is cached and returned. The filtered value is passed through wp_kses_post().

Parameters:

ParameterTypeDescription
$outputstringThe rendered HTML output.
$resultarray|nullRaw query result row for single-value types; null for list types.
$attsarrayFull sanitized shortcode attributes.

Example:

add_filter( 'burst_statistics_shortcode_output', function( $output, $result, $atts ) {
if ( $atts['type'] === 'pageviews' ) {
$output = '<div class="my-wrapper">' . $output . '</div>';
}

return $output;
}, 10, 3 );

burst_most_visited_count

Filters the view count displayed next to each post in the most_visited list when show_count="true".

Parameters:

ParameterTypeDescription
$countintThe raw view count for the post.
$postWP_PostThe post object.

Example:

add_filter( 'burst_most_visited_count', function( $count, $post ) {
return $count . ' views';
}, 10, 2 );

Caching

Shortcode output is cached using WordPress transients. The cache key is derived from a hash of all shortcode attributes, the resolved date range, and the plugin version, so each unique combination of parameters has its own cache entry.

  • Default cache duration: 3600 seconds (1 hour).
  • Set cache_duration="0" to disable caching entirely.
  • Caching is automatically bypassed when WP_DEBUG is true.
  • Cache is automatically invalidated when the plugin version changes.

Stylesheet

The shortcode stylesheet (assets/css/shortcodes.css) is registered on wp_enqueue_scripts but only enqueued when a post's content contains a [burst_statistics] or [burst-most-visited] shortcode. It is not loaded on pages that do not use these shortcodes.