Fix post view in lightspeed cache




Wordpress LScache Plugin: Fix post view in lightspeed cache

Last Updated on: Wed, 15 Apr 2026 00:00:02
Hi I used this tutorial for track post view on WP But when I enable Light Speed Cache , it does not work! How to fix it? The page I need help with: https://wp-snippet.com/snippets/track-show-post-views-without-plugin/ This kind of track cant work with cache. Please try an ajax track way. thanks for your quick replay is there Fragment Caching in light speed cache? in this tutorial it fix it on W3 total cach Yes in LSCWP its called ESI: https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:esi_sample Please try the following code: 1. Change setPostViews(get_the_ID()) to LiteSpeed_Cache_API::hook_tpl_esi(your_count_esi, hook_esi ) function hook_esi( $param ) setPostViews( $param[ id ] ) exit echo LiteSpeed_Cache_API::esi_url( your_count_esi, RezaY test, array( id => get_the_ID() ) ) it didnt work. it echo a list of may recent post! For LiteSpeed_Cache_API::hook_tpl_esi(your_count_esi, hook_esi ) function hook_esi( $param ) setPostViews( $param[ id ] ) exit part, please put into functions.php. It needs a higher priority to run, before all theme codes output. I put these in function.php function getPostViews($postID) $count_key = post_views_count $count = get_post_meta($postID, $count_key, true) if ($count == ) delete_post_meta($postID, $count_key) add_post_meta($postID, $count_key, 0) return 0 View return $count . Views function setPostViews($postID) $count_key = post_views_count $count = get_post_meta($postID, $count_key, true) if ($count == ) $count = 0 delete_post_meta($postID, $count_key) add_post_meta($postID, $count_key, 0) else $count++ update_post_meta($postID, $count_key, $count) // Remove issues with prefetching adding extra views remove_action(wp_head, adjacent_posts_rel_link_wp_head, 10, 0) LiteSpeed_Cache_API::hook_tpl_esi(your_count_esi, hook_esi ) function hook_esi( $param ) setPostViews( $param[ id ] ) exit Expand and this in single php `



LiteCache Rush: Speed comes from using less, not from doing it faster



Reference