Title: Views today shortcode
Last modified: November 9, 2021

---

# Views today shortcode

 *  Resolved [pknack](https://wordpress.org/support/users/pknack/)
 * (@pknack)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/views-today-shortcode/)
 * Hello.
 * Is there any option to display today’s website statistics as a shortcode? I want
   to insert it into the page
 * Thanks!

Viewing 1 replies (of 1 total)

 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [4 years, 6 months ago](https://wordpress.org/support/topic/views-today-shortcode/#post-15050195)
 * My plugin does not do this out of the box, but you could use the following code
   snippet, [added in a functionality plugin](https://jetpack.com/support/adding-code-snippets/),
   to create a new `jp_post_view_today` shortcode:
 *     ```
       add_shortcode(
       	'jp_post_view_today',
       	function () {
       		// Get the post ID.
       		$post_id = get_the_ID();
   
       		if ( ! isset( $post_id ) || empty( $post_id ) ) {
       			return;
       		}
   
       		if ( ! function_exists( 'stats_get_from_restapi' ) ) {
       			return;
       		}
   
       		// Get extra views for that post ID.
       		$stats = stats_get_from_restapi(
       			array( 'fields' => 'views' ),
       			sprintf(
       				'post/%d',
       				$post_id
       			)
       		);
   
       		$today_data = array();
       		if (
       			isset( $stats )
       			&& ! empty( $stats )
       			&& isset( $stats->data )
       		) {
       			$today_data = end( $stats->data );
       		}
   
       		if ( empty( $today_data ) || ! isset( $today_data[1] ) ) {
       			return esc_html__( 'no views', 'post-views-for-jetpack' );
       		}
   
       		return sprintf(
       			esc_html(
       				_n(
       					'%s view today',
       					'%s views today',
       					$today_data[1],
       					'post-views-for-jetpack'
       				)
       			),
       			number_format_i18n( $today_data[1] )
       		);
       	}
       );
       ```
   
 * You can then use that shorcode in your posts, or use the method I highlighted
   here to use that shortcode in your theme:
    [https://wordpress.org/plugins/post-views-for-jetpack/#faq](https://wordpress.org/plugins/post-views-for-jetpack/#faq)

Viewing 1 replies (of 1 total)

The topic ‘Views today shortcode’ is closed to new replies.

 * ![](https://ps.w.org/post-views-for-jetpack/assets/icon-256x256.png?rev=1518414)
 * [Post Views for Jetpack](https://wordpress.org/plugins/post-views-for-jetpack/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/post-views-for-jetpack/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/post-views-for-jetpack/)
 * [Active Topics](https://wordpress.org/support/plugin/post-views-for-jetpack/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/post-views-for-jetpack/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/post-views-for-jetpack/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * Last activity: [4 years, 6 months ago](https://wordpress.org/support/topic/views-today-shortcode/#post-15050195)
 * Status: resolved