• Resolved lotfreeman

    (@lotfreeman)


    Started using your plugin, works great!
    Understood with snippets.
    Can you tell me where to put this code <?php echo do_shortcode( '[jp_post_view]' ); ?>
    where is the topic? Theme: Kadence
    I would like to display the views on the post card, and not inside the page or post that the views from your plugin were visible
    
    I ask for your advice!
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    I would recommend that you do not edit your theme files directly. If you do that, your changes would disappear the next time you update to a new version of the theme.

    Instead, you can use a plugin like this one to add code to your site. You can then choose where that code will be hooked into your theme. Your theme, Kadence, offers a lot of hooks, places where you can inject content.

    You can, for example, decide to inject content right after the entry meta data, like on this screenshot:

    Would that work for you? To do that, you would add the following code to the Code Snippets plugin I mentioned above:

    add_action(
    	'kadence_after_loop_entry_meta',
    	function () {
    		printf(
    			'<span class="views">%s</span>',
    			do_shortcode( '[jp_post_view]' )
    		);
    	}
    );

    Let me know if it helps!

    Thread Starter lotfreeman

    (@lotfreeman)

    Thanks, the code worked great. I admire you, you are a true professional!
    Your plugin is seriously slowing down the site. Found out today by running a speed test, can you fix it?

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Could you check if you are running the latest version of the plugin, version 1.5.0? I made some changes to improve performance in that version, so that should help.

    Beyond those changes, the plugin will have an impact on performance indeed, especially if you display multiple counters on the same page (like with the code snippet above). The plugin does cache data to help with performance, but the first time the page is loaded it will be slow since it needs to fetch your stats data from WordPress.com, for each post with a counter on the page.

    If you’d like to cache data even more aggressively on your site to further improve performance, you can add the following code snippet to your site:

    /**
     * Cache post views for 6 hours.
     */
    add_filter(
    	'jp_post_views_cache_duration',
    	function () {
    		return 6 * HOUR_IN_SECONDS;
    	}
    );

    Note, however, that if you add the following snippet, the number of views will only be refreshed every 6 hours on your site.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Question of code’ is closed to new replies.