Last active
May 5, 2024 02:49
-
-
Save jeherve/6328c232f91977a6924805d93490c152 to your computer and use it in GitHub Desktop.
[Post Views For Jetpack] Display a Stats counter at the top of every post, with a "Views:" heading.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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