Loading post comments after clicking a button

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.

Read More

How could I achieve that?

Related posts

Leave a Reply

3 comments

  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.

  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