• Resolved sanchitgogia

    (@sanchitgogia)


    Hi There,

    With the help of WP team, we’ve been able to activate this plugin which is currently great (thanks for making this!), but it’s being shown at the end of each post/page. May I please request your help with a few things?

    1 – can we please show this post views at the start of the post – alongside the reading time? and in one line – the way currently reading time is displayed?

    2 – the views count is currently also showing on pages – is there a way to switch that off?

    3 – the views is currently also being shown on the home page – can we switch this off?

    Thanks, for all your support and help. Truly appreciate it.

    Cheers.

    The blog I need help with is greyhoundresearch.com.

    The page I need help with: [log in to see the link]

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

    (@jeherve)

    Jetpack Mechanic 🚀

    I see you’ve already added a snippet to add the post views to every post on your site. That’s a great start. You can now tweak that snippet a bit to:

    1. Ensure the views do not appear on the home page.
    2. Ensure the views only appear on posts (not on pages)
    3. Add the views to the top of the post, instead of the bottom

    Here is the snippet you could use to do just that:

    /**
     * Display a Stats counter at the top of every post.
     * @see https://wordpress.org/support/topic/page-views-off/
     *
     * @param string $content Post content.
     */
    function jeherve_sanchitgogia_add_counter_to_posts( $content ) {
    	$post_views = sprintf(
    		'<span class="stats_counter rt-reading-time" style="display:inline">
    			<span class="rt-time">%1$s</span>
    		</span>',
    		esc_html( do_shortcode( '[jp_post_view]') )
    	);
    
    	/*
    	 * Add to the top of each single post
    	 * but not on pages or on the homepage.
    	 */
    	if ( is_singular( 'post' ) ) {
    		return $post_views . $content;
    	}
    
    	// Final fallback.
    	return $content;
    }
    add_filter( 'the_content', 'jeherve_sanchitgogia_add_counter_to_posts' );

    In addition to this, you could go to Appearance > Customize > CSS to customize things further and ensure that both the reading time and the number of views look well together.

    /* Ensure that both the reading time and the stats can fit on one line. */
    .single-post span.rt-reading-time {
    	display: inline !important;
    }
    
    /* Add a | before the stats counter */
    .single-post .stats_counter:before {
    	content: ' |';
    }
    
    /* Add a bit of margin before the actual post content on single posts. */
    .single-post .entry-content p:first-of-type {
    	margin-top: 2rem;
    }

    I hope this helps.

    Thread Starter sanchitgogia

    (@sanchitgogia)

    Thanks much, Jeremy, this is super helpful. Few things, please:

    1/ Can still see the views on the pages – for reference please see this – https://greyhoundresearch.com/how-we-help/ – can you please help remove the views on the pages?

    2/ Can still see the views on the homepage – please see https://greyhoundresearch.com – can you please help remove the views on the homepage?

    3/ On the posts – can we please move the ‘|’ to post the number of views? essentially between number of views and reading time

    4/ On the posts – can we please switch off the views at the bottom of the posts? Cause it’s still visible.

    Thanks much for your help. This is a brilliant plugin!

    Thread Starter sanchitgogia

    (@sanchitgogia)

    Please avoid request #3, have managed to address it. Thank you.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    1, 2, 3, and 4 still exist because you haven’t removed the code snippet you were previously using; you’d need to remove it since you’ve added the snippet I provided you instead.

    Thread Starter sanchitgogia

    (@sanchitgogia)

    ah, got it, thank you, Jeremy! Your help is much appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Page Views Off’ is closed to new replies.