2014-05-27 18:32:57 -04:00
---
2014-05-29 18:42:05 -04:00
date: 2014-05-26
linktitle: Comments
2014-05-27 18:32:57 -04:00
menu:
main:
2014-05-29 18:42:05 -04:00
parent: extras
2014-11-25 03:07:18 -05:00
next: /extras/crossreferences
2014-05-29 18:42:05 -04:00
prev: /extras/builders
title: Comments in Hugo
2014-11-25 03:07:18 -05:00
weight: 30
2014-05-27 18:32:57 -04:00
---
As Hugo is a static site generator, the content produced is static and
doesn’ t interact with the users. The most common interaction people ask
for is comment capability.
2015-01-27 21:17:09 -05:00
Hugo ships with support for [Disqus ](https://disqus.com/ ), a third-party
2014-05-27 18:32:57 -04:00
service that provides comment and community capabilities to website via
2014-10-07 19:52:58 -04:00
JavaScript.
2014-05-27 18:32:57 -04:00
2014-10-07 19:52:58 -04:00
Your theme may already support Disqus, but even it if doesn’ t, it is easy
2014-05-27 18:32:57 -04:00
to add.
# Disqus Support
## Adding Disqus to a template
2014-10-07 19:52:58 -04:00
Hugo comes with all the code you would need to include load Disqus.
Simply include the following line where you want your comments to appear:
2014-05-27 18:32:57 -04:00
{{ template "_internal/disqus.html" . }}
## Configuring Disqus
2014-09-03 00:12:26 -04:00
That template requires you to set a single value in your site config file, e.g. config.yaml.
2014-05-27 18:32:57 -04:00
disqusShortname = "XYW"
2014-10-07 19:52:58 -04:00
Additionally, you can optionally set the following in the front matter
for a given piece of content:
2014-05-27 18:32:57 -04:00
* **disqus_identifier**
* **disqus_title**
* **disqus_url**
2014-06-06 01:32:06 -04:00
## Conditional Loading of Disqus Comments
2014-10-07 19:52:58 -04:00
Users have noticed that enabling Disqus comments when running the Hugo web server on localhost causes the creation of unwanted discussions on the associated Disqus account. In order to prevent this, a slightly tweaked partial template is required. So, rather than using the built-in `"_internal/disqus.html"` template referenced above, create a template in your `partials` folder that looks like this:
2014-06-06 01:32:06 -04:00
```javascript
< div id = "disqus_thread" > < / div >
< script type = "text/javascript" >
(function() {
2014-10-07 19:52:58 -04:00
// Don't ever inject Disqus on localhost--it creates unwanted
// discussions from 'localhost:1313' on your Disqus account...
if (window.location.hostname == "localhost")
2014-06-06 01:32:06 -04:00
return;
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
var disqus_shortname = '{{ .Site.Params.disqusShortname }}';
dsq.src = '//' + 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 >
2015-01-27 21:17:09 -05:00
< a href = "http://disqus.com/" class = "dsq-brlink" > comments powered by < span class = "logo-disqus" > Disqus< / span > < / a >
2014-06-06 01:32:06 -04:00
```
2014-10-07 19:52:58 -04:00
Notice that there is a simple `if` statement that detects when you are running on localhost and skips the initialization of the Disqus comment injection.
2014-06-06 01:32:06 -04:00
2014-10-07 19:52:58 -04:00
Now, reference the partial template from your page template:
2014-06-06 01:32:06 -04:00
2014-09-03 00:12:26 -04:00
{{ partial "disqus.html" . }}
2014-06-06 01:32:06 -04:00
2014-05-27 18:32:57 -04:00
# Alternatives
2015-01-27 21:17:09 -05:00
A few alternatives exist to [Disqus ](https://disqus.com/ ):
2014-05-27 18:32:57 -04:00
2014-12-24 06:55:11 -05:00
* [IntenseDebate ](http://intensedebate.com/ )
* [Livefyre ](http://livefyre.com/ )
2015-01-27 21:17:09 -05:00
* [Muut ](http://muut.com/ )
2014-10-07 19:52:58 -04:00
* [多说 ](http://duoshuo.com/ ) ([Duoshuo](http://duoshuo.com/), popular in China)
2015-04-02 04:16:18 -04:00
* [isso ](http://posativ.org/isso/ ) (Self-hosted, Python)
2015-01-27 21:17:09 -05:00
* [Kaiju ](https://github.com/spf13/kaiju )
2014-05-27 18:32:57 -04:00
2015-01-27 21:17:09 -05:00
[Kaiju ](https://github.com/spf13/kaiju ) is an open-source project started
by [spf13 ](http://spf13.com/ ) (Hugo’ s author) to bring easy and fast real
2014-05-27 18:32:57 -04:00
time discussions to the web.
2014-10-07 19:52:58 -04:00
Written using Go, Socket.io and MongoDB, it is very fast and easy to
2014-05-27 18:32:57 -04:00
deploy.
2014-10-07 19:52:58 -04:00
It is in early development but shows promise. If you have interest,
2014-05-27 18:32:57 -04:00
please help by contributing whether via a pull request, an issue or even
just a tweet. Everything helps.