• Resolved senguyen

    (@senguyen)


    Hello.

    Is there any option to display All Time Site Stats as shortcode? I want to insert it into the page.

    Thanks!

Viewing 1 replies (of 1 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    There is no such option, but you can use the following snippet in a functionality plugin to create an [jp_all_time_stats] shortcode you’ll then be able to use:

    /**
     * Create a shortcode to display the All Time Stats widget anywhere.
     *
     * @see https://www.ads-software.com/support/topic/all-time-site-stats-shortcode/
     */
    function jeherve_display_all_stats_shortcode() {
    	if ( ! function_exists( 'jp_post_views_get_all_views' ) ) {
    		return '';
    	}
    
    	// Get the Site Stats.
    	$views = jp_post_views_get_all_views();
    
    	if ( isset( $views ) && ! empty( $views ) ) {
    		$output = sprintf(
    			esc_html(
    				_n(
    					'%s view',
    					'%s views',
    					$views['total'],
    					'post-views-for-jetpack'
    				)
    			),
    			number_format_i18n( $views['total'] )
    		);
    	} else {
    		$output = esc_html__( 'No views', 'post-views-for-jetpack' );
    	}
    
    	return $output;
    }
    add_shortcode( 'jp_all_time_stats', 'jeherve_display_all_stats_shortcode' );
Viewing 1 replies (of 1 total)
  • The topic ‘All Time Site Stats shortcode’ is closed to new replies.