1

Is it possible to load site comments on-demand instead of having them always display at the bottom of the post? Like by clicking on Load Comments....

You can check labnol.org. They are using Disqus comment system which loads by clicking.

How could I achieve that?

0

You could try an easy jQuery approach of hiding the comments div and inserting a button to make it appear.

Instructions:

In your functions.php file of your theme, place this line of code to ensure that jQuery has been included to run the code:

wp_enqueue_script('jquery');

Then you could add this function to place the javascript code into the footer of each of your webpages:

function your_hidden_comments(){ ?>
<script type="text/javascript" defer="defer">
var comment_div = jQuery('#comments');
if(comment_div[0]){

    jQuery('<button id="show_comments">Show Comments</button>').insertBefore(comment_div);

    comment_div.hide();

    jQuery('#show_comments').on('click',function(){ comment_div.fadeIn('slow'); jQuery('#show_comments').fadeOut('slow'); });
}
</script>
<?php } 

add_action('wp_footer', 'your_hidden_comments');

I hope that helps; comment back if there is any trouble with this.

  • sir i'm not getting it where and how to add it its a bit confusing would you kindly clarify me a bit should i use it like this ..... <?php wp_enqueue_script("jquery"); ?> <?php wp_footer(); ?> <script type="text/javascript"> var comment_div = jQuery('#comments'); jQuery('<button id="show_comments" value="show_comments"></button>').prependTo(comment_div); comment_div.hide(); jQuery('#show_comments').on('click',function(){ comment_div.fadeIn('slow'); jQuery('#show_comments').fadeOut('slow'); }); }); </script> – Arafin Shaon Sep 12 '12 at 3:05
  • Just made an edit; I hope that helps. – Douglas.Sesar Sep 12 '12 at 4:02
  • Tnx for your effort. I tried it on wordpress 2011 theme but unfortunately not working. Even after installed disqus commenting system….. – Arafin Shaon Sep 12 '12 at 13:05
  • If you are using chrome, right-click and select 'inspect element'. Then select the 'console' tab and let me know what the javascript error says (if there is one) – Douglas.Sesar Sep 12 '12 at 15:24
  • After adding the code my comments being hidden but load comments button is not appearing to make them loading and console is showing error.... "Failed to load resource" – Arafin Shaon Sep 12 '12 at 18:12
2

Since you are using WordPress, you can make use of the Lazy Load for Comments plugin which is available for free from WordPress.org plugin repository. It allows you to lazy load WordPress default commenting system without any complex configurations. It also helps you to get rid of unwanted HTTP requests and makes sure you get your page speed back.

Click to Load Comments

0

This plugin doesn't do it "on click", but it does modify the comment system to load comments after the page has loaded, giving you faster initial page load times.

http://wordpress.org/extend/plugins/ajax-comment-loading/

Works well, I use it on many sites.

  • this is not what i'm looking i want my comments to be hidden – Arafin Shaon Sep 14 '12 at 5:14

protected by Community Jun 28 '18 at 12:42

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.