Skip to content

Instantly share code, notes, and snippets.

@ythecombinator
Created May 27, 2015 23:59
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ythecombinator/dc245da48a757b91b777 to your computer and use it in GitHub Desktop.
Save ythecombinator/dc245da48a757b91b777 to your computer and use it in GitHub Desktop.
Simple tip for adding "Disqus" comments for Hexo.

In the footer of your theme (something like footer.ejs) you should add Disqus script:

<% if (config.disqus_shortname){ %>
<script>
  var disqus_shortname = '<%= config.disqus_shortname %>';
  <% if (page.permalink){ %>
  var disqus_url = '<%= config.url +"/"+ page.path %>';
  <% } %>
  (function(){
    var dsq = document.createElement('script');
    dsq.type = 'text/javascript';
    dsq.async = true;
    dsq.src = '//' + disqus_shortname + '.disqus.com/<% if (page.comments) { %>embed.js<% } else { %>count.js<% } %>';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
</script>
<% } %>

Don't forget that Hexo is prepared to use Disqus, so you the another missing thing is to enable it in your _config.yml

# Disqus
disqus_shortname: username
@kiarafbickers
Copy link

How would I get just the comment count number?

@arbaev
Copy link

arbaev commented May 30, 2017

@kiarafrobles check this instructions: https://help.disqus.com/customer/portal/articles/565624

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment