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?

1

3 Answers 3

1

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.

15
  • 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> Sep 12, 2012 at 3:05
  • Just made an edit; I hope that helps. Sep 12, 2012 at 4:02
  • Tnx for your effort. I tried it on wordpress 2011 theme but unfortunately not working. Even after installed disqus commenting system….. Sep 12, 2012 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) Sep 12, 2012 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" Sep 12, 2012 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.

1
  • this is not what i'm looking i want my comments to be hidden Sep 14, 2012 at 5:14

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