DEV Community

Waldemar Panas
Waldemar Panas

Posted on • Originally published at on


How to add Disqus to your GitHub Pages

Add a partial with Disqus

Create a file _includes/disqus.html with following content. Then you need to replace YOUR_DISQUS_NAME with shortname that is identifying your website on Disqus.

{% if page.comments %}
<div id="disqus_thread"></div>
var disqus_shortname = YOUR_DISQUS_NAME;
var disqus_config = function () { = "{{page.url | absolute_url }}"; = "{{}}";

(function() {
var d = document, s = d.createElement('script');
s.src = 'https://' + disqus_shortname + '';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
<noscript>Please enable JavaScript to view the <a href="">comments powered by Disqus.</a></noscript>
{% endif %}

Create a layout with comments

In folder _layouts create a new HTML file blog.html. This layout will be extending default post layout with previously created partial.

layout: 'post'

{{ content }}

{% include disqus.html %}

Configure the new layout for all your posts

Now all you need to do to enable Disqus in your post is:

  • set blog as default layout for your posts,
  • enable flag comments by default.

To do so append file _config.yml with that configuration.

      path: ""
      type: "posts"
      layout: "blog"
      comments: true

How to disable comments in selected post

Change comments flag to false at the begging of post file.

title: "My post without comments"
comments: false

Latest comments (0)

18 Useful Github Repositories Every Developer Should Bookmark

18 Useful GitHub repositories every developer should bookmark: everything from learning resources and roadmaps to best practices, system designs, and tools.