How to Load Disqus Comments on Demand?

    Most WordPress sites use Disqus as their commenting system. The easiest way to implement Disqus on your website is to use their plugin.

    Since Disqus loads asynchronously, your web page load speeds are not affected. However, Disqus downloads required files to the user’s system, which adds the weight of posts/pages where you have implemented Disqus codes. This costs your users their valuable bandwidth.

    There are numerous other posts on the internet related to the topic. The one I liked the most is from Labnol. However, in his post, he didn’t mention how to dynamically get post URL, post ID, etc. We bring you a code snippet that you can place in your theme’s “functions.php” file.

    STEP 1

    Place the below code in your theme’s “functions.php” file or your site-specific plugin. Remember to change the short name from “aneejian” to your Disqus short name – line highlighted in code
    var disqus_shortname = "your disqus short name";

    function disqus_embed() {
    	global $post;
        echo '<script type="text/javascript">
        var disqus_shortname = "aneejian";
        var disqus_title = "'.$post->post_title.'";
        var disqus_url = "'.get_permalink($post->ID).'";
        var disqus_identifier = "'.$disqus_shortname.'-'.$post->ID.'";
        var disqus_loaded = false;
        function loadDisqus() {
          if (!disqus_loaded)  {
            disqus_loaded = true;
            var e = document.createElement("script");
            e.type = "text/javascript";
            e.async = true;
            e.src = "//" + disqus_shortname + "";
            (document.getElementsByTagName("head")[0] ||
    add_action('wp_head', 'disqus_embed');

    STEP 2

    Place the below code where you want Disqus to load. This will show a link “Load Comments” where you have placed the code. Clicking the link will load comments.
    You can place it in your theme’s “comments.php” file or “single.php” file or you can use a plugin that can insert codes to your post/pages.

    <div id="disqus_thread">
      <a href="#" onclick="loadDisqus();return false;">Load Comments</a> 

    Related Articles

    Recent Articles

    How to fix Date Time data type issue in Blue Prism?

    Know more about the date time issue while using the code stage in Blue Prism and understand how to fix it by dealing with the UTC offset.

    How to deserialize JSON in UiPath?

    Tutorial on how to properly deserialize JSON with UiPath Web Activities. Explains the concept of JSON Array and JSON Object.

    Dynamic or Variable Selectors in UiPath

    Tutorial on how to use dynamic selectors in UiPath. Explains how to use variables in UiPath selectors.

    Change Case Excel Add-In

    Change Case Excel Add-In is a powerful Excel Add-In that can change the case of selected cells. With easy to use Keyboard shortcuts, perform case conversion in style.

    Blue Prism Video Tutorial

    A well-structured video tutorial on Blue Prism, which is the right starting point for your RPA career. #rpa #blueprism

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Stay on top - Get latest articles in your inbox