Skip to content

Instantly share code, notes, and snippets.

@jeherve

jeherve/plugin.php

Last active Dec 8, 2020
Embed
What would you like to do?
[Post Views For Jetpack] Display a Stats counter at the top of every post, with a "Views:" heading.
<?php
/**
* Display a Stats counter at the top of every post, with a "Views:" heading.
* @see https://wordpress.org/support/topic/page-views-off/
*
* @param string $content Post content.
*/
function jeherve_custom_display_post_views( $content ) {
$post_views = sprintf(
'<div class="stats_counter sd-content"><h3 class="sd-title">%1$s</h3><div class="sd-content">%2$s</div></div>',
esc_html__( 'Views:', 'jetpack' ),
esc_html( do_shortcode( '[jp_post_view]') )
);
/*
* Add to the bottom of each single post
* but not on pages or on the homepage.
*/
if ( is_singular( 'post' ) ) {
return $content . $post_views;
}
return $content;
}
add_filter( 'the_content', 'jeherve_custom_display_post_views' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment