Adding Disqus to a Jekyll Blog
A Jekyll blog is not backed by a database. Out of the box, there is no way for people to comment on or discuss blog posts. Disqus is a third party service that can be used to get around that limitation. This post covers adding Disqus to a Jekyll blog.
Software Versions
$ date
February 15, 2016 at 05:56:57 PM JST
$ uname -vm
FreeBSD 11.0-CURRENT #0 r287598: Thu Sep 10 14:45:48 JST 2015 root@:/usr/obj/usr/src/sys/MIRAGE_KERNEL amd64
$ ruby --version
ruby 2.1.8p440 (2015-12-16 revision 53160) [amd64-freebsd11]
$ jekyll --version
jekyll 3.0.1Instructions
First, install Jekyll and register your site with Disqus.
Add the following code to _includes/disqus.html. Remember to change the this.page.url line to the URL of your blog. The s.src line will need to point to your Disqus short name URL. Consider copying the Universal Embed Code directly from Disqus instead of this post.
{% if page.comments %}
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = "http://BLOG.host.com{{ page.url }}"; // <--- use canonical URL
this.page.identifier = "{{ page.id }}";
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = '//SHORTNAME.disqus.com/embed.js'; // <--- use Disqus shortname
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
{% endif %}Add the following line to the end of _layouts/post.html or anywhere else you want to display comments.
{% include disqus.html %}Add the following line to the YAML front matter of a post to enable comments on a post by post basis.
comments: trueFor example, the front matter of this post looks like this.
---
layout: post
comments: true
title: "Adding Disqus to a Jekyll Blog"
date: 2016-02-15 05:56:57 +0900
categories: jekyll disqus
---Optionally, to facilitate displaying comment counts add the following to _layouts/default.html before the closing body tag. Change SHORTNAME to the Disqus shortname you are using.
<script id="dsq-count-scr" src="//SHORTNAME.disqus.com/count.js" async></script>Add #disqus_thread to the end of a URL and Disqus will count the comments on the page the link points to. For example, my _layouts/post.html contains the following code. Note the comment count at the top of this post.
{% if page.comments %} • <a href="https://sgeos.github.io{{ page.url }}#disqus_thread">0 Comments</a>{% endif %}index.html contains the following code to display the comment count for each post in the list.
<a href="https://sgeos.github.io{{ post.url }}#disqus_thread">0 Comments</a>Note that moving a post from _drafts/ to _posts/ may change the URL of the post. This will cause any comments added to the draft to disappear. The Disqus Migration Tools can be used move comments to the new URL.
References
Primary Sources, Non-Peer-Reviewed
- “Disqus, Jekyll Installation Instructions.” n.d. help.disqus.com. Accessed October 25, 2026. https://help.disqus.com/customer/portal/articles/472138-jekyll-installation-instructions
- “Disqus, Use Configuration Variables to Avoid Split Threads and ‘Missing’ Comments.” n.d. help.disqus.com. Accessed October 25, 2026. https://help.disqus.com/customer/en/portal/articles/2158629
- “Front Matter.” 2016. Jekyll • Simple, blog-aware, static sites. Accessed October 25, 2026. http://jekyllrb.com/docs/frontmatter/
- “Jekyll.” n.d. jekyllrb.com. Accessed October 25, 2026. https://jekyllrb.com
- “Migration Tools.” n.d. DISQUS. Accessed October 25, 2026. https://help.disqus.com/customer/portal/articles/286778-migration-tools
- “Templates.” n.d. jekyllrb.com. Accessed October 25, 2026. http://jekyllrb.com/docs/templates/
- “Variables.” n.d. jekyllrb.com. Accessed October 25, 2026. http://jekyllrb.com/docs/variables/
Commercial Sources
- “Disqus.” n.d. Accessed October 25, 2026. https://disqus.com
- “Disqus, Set Up Disqus On a New Site.” n.d. Accessed October 25, 2026. https://disqus.com/admin/create/
- “Install Instructions for Universal Code.” n.d. Accessed October 25, 2026. https://disqus.com/admin/universalcode/
- “Use Canonical URLs: Search Console Help.” n.d. Accessed October 25, 2026. https://support.google.com/webmasters/answer/139066?hl=en
General Sources
- “Adding Disqus to Your Jekyll.” n.d. Perfectly Random. Accessed October 25, 2026. http://www.perfectlyrandom.org/2014/06/29/adding-disqus-to-your-jekyll-powered-github-pages/
- “Dynamic Links in Jekyll.” n.d. Accessed October 25, 2026. http://stackoverflow.com/questions/22725754/dynamic-links-in-jekyll
- Haack, Phil. n.d. “Preserve Disqus Comments with Jekyll.” Accessed October 25, 2026. http://haacked.com/archive/2013/12/09/preserving-disqus-comments-with-jekyll/
- “How I Created a Beautiful and Minimal Blog Using Jekyll, Github Pages, and Poole · Joshua Lande.” n.d. Accessed October 25, 2026. http://joshualande.com/jekyll-github-pages-poole/
- “Jekyll Notes · Sound/Noise.” n.d. Accessed October 25, 2026. http://blog.pzheng.me/2014/07/03/Jekyll-Notes/
- Tesoriere, Scott. n.d. “Highlighting Liquid Code in a Liquid Template with Jekyll (Escape a Liquid Templating Tag).” Accessed October 25, 2026. http://tesoriere.com/2010/08/25/liquid-code-in-a-liquid-template-with-jekyll/
Related Posts
- Sechter, Brendan. 2016. “Creating A Jekyll GitHub Pages Blog and Managing it With FreeBSD.” Brendan A R Sechter’s Development Blog, January 8. https://sgeos.github.io/jekyll/github/freebsd/2016/01/08/creating-a-jekyll-github-pages-blog-and-managing-it-with-freebsd.html
Referenced by
- Adding MathJax to a GitHub Pages Jekyll Blog 2016-08-21