Docs

Universal Code

Disqus can be installed on virtually any website using the universal JavaScript embed code. The following documentation is meant for developers only. Disqus also provides installation instructions for dozens of popular blogging and website platforms such as WordPress, Blogger, and more.

Before you start

  • Make sure you've registered your website with Disqus. Read the Quickstart Guide for more information.
  • You will need to be able to edit the HTML of the website you are installing Disqus on.
  • To install Disqus, you will need to know your forum shortname as registered on Disqus.

You are not logged in. You must register your website with Disqus before installing the system. To learn more read the QuickStart guide.

Embed code

This is the JavaScript embed code which loads and displays Disqus on your site, typically on the individual article or post pages.

Note: Don't forget to change 'example' to your forum's shortname (listed above).

<div id="disqus_thread"></div>
<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'example'; // required: replace example with your forum shortname

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>

Configuration variables

Within the above embed code, there are configuration variables which tell Disqus how the system should work and behave.

disqus_shortname tells Disqus which website account (called a forum on Disqus) this system belongs to.

disqus_identifier tells Disqus how to uniquely identify the current page.

disqus_url tells Disqus the location of the page for permalinking purposes.

There are many more configuration variables available, but these are the most important. To learn more about these and the other configuration variables, read JavaScript configuration variables.

Comment count

Most websites implementing Disqus will want a way to display the comment counts on the index page. We offer an easy to use JavaScript code snippet which displays the number of comments for pages with Disqus embedded.

The following is the code that should be included on a page which needs to display the comment counts (typically this is the index page of your blog or website). The code should be included at the bottom of the webpage, right before the closing </body> tag,

<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'example'; // required: replace example with your forum shortname

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function () {
        var s = document.createElement('script'); s.async = true;
        s.type = 'text/javascript';
        s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
        (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
    }());
</script>

Next, you need to tell Disqus which links to look up and return the comment count. You can do this by appending #disqus_thread to the end of the href attribute of your links.

Disqus can look up the comment count by the URL or by a Disqus identifier. Specifying a Disqus identifier is highly recommended. To do this, add a special attribute data-disqus-identifier to your links. If you cannot use Disqus identifiers with your install of Disqus (e.g. static webpages), you can simply not add this attribute and Disqus will look up threads by the URLs in the href attributes of the links. Since URLs can change, we highly recommend using the Disqus identifier.

Examples for using the comment code script

For the following link, Disqus will fetch the comment count by the identifier: article_1_identifier <a href="http://example.com/article1.html#disqus_thread" data-disqus-identifier="article_1_identifier">First article</a>

For the following link, Disqus will fetch the comment count by the URL: http://example.com/article2.html <a href="http://example.com/article2.html#disqus_thread">Second article</a>

Disqus will ignore the following link because its href attribute does not end with #disqus_thread <a href="http://example.com/" data-disqus-identifier="over-9000">Anchor</a>

The recommended approach is to use the identifier (the first example) because this is most consistent.

Further reading / FAQ

Posted In Developers Last updated Nov. 10, 2011