Home > How To's/Reviews > WordPress Cached Disqus Recent Comments Widget

WordPress Cached Disqus Recent Comments Widget

Thanks to the Disqus Recent Comments Widget, WordPress users can easily display recent Disqus comments through sidebar widgets; however, for dynamic sites with significant activity, Disqus API requests can prove to be cumbersome. What if you exceed the allotted requests per hour? How slow will fetching recent comments make page loads? This is where WordPress’ Transient API comes in handy!

After installing the plugin, open wp-content/plugins/disqus-recent-comments-widget/disqus_recent_comments_widget.php. I recommend copying over the latest developmental code from here. Around line 250, add the lines below to the very beginning of the echo_comments function.

protected function echo_comments($comment, $api_key, $style_params,$args=false) {
	$cached = get_transient($SITEDISQUS);
	if (false !== $cached){echo $cached;return;}

Now scroll to around line 360 where the function ends. Add the set_transient code right above the final ‘echo’ output.

set_transient($SITEDISQUS, $recent_comments, 600);

Essentially, the modified function will check to see if your comments are stored in a transient ($SITEDISQUS). If yes, then the function will terminate early with the transient output. If the transient has expired (in the example above, ‘600’ refers to 600 seconds), the function will be executed, and the transient data will be refreshed for another 600 seconds.

Let me know if you have questions or if this helped! 馃檪


My posts are not to serve as a replacement for recommendations provided by licensed physicians nor do they represent the opinions of Baylor College of Medicine or its affiliated institutions. Please read this site's Disclaimer and Terms of Use for more information.


First Impressions of Google’s Pixel Smartphone – Upgrading From Nexus 6P

Even a year later, the Nexus 6P is still a superb smartphone. It was the …


  1. That was exactly what i was searching!!! Thanks so much for this article!!!


Your email address will not be published. Required fields are marked *