{{craftSnippets}}
Home Articles Plugins Starter theme Components on Github Gists About
  • Home
  • Articles
  • How to add Disqus comments to Craft CMS website
Posted on May 17, 2019 by Piotr Pogorzelski

How to add Disqus comments to Craft CMS website

Disqus Twig component on github gists
In this article, you will learn how to set up Disqus comments on your Craft CMS website - without the use of any plugins.

First, you need to set up Disqus account and obtain your unique shortname. After that, just include this Twig component in a place where comments should appear. Don't forget to set shortname variable!

{% set shortname = 'YOUR_WEBSITE_SHORTNAME' %}
{% if entry is defined %}
    <div id="disqus_thread"></div>
    <script>
    var disqus_config = function () {
    this.page.url = '{{entry.url}}';  
    this.page.identifier = '{{entry.id}}'; 
    this.page.title = '{{entry.title}}';
    };
    (function() { // DON'T EDIT BELOW THIS LINE
    var d = document, s = d.createElement('script');
    s.src = 'https://{{shortname}}.disqus.com/embed.js';
    s.setAttribute('data-timestamp', +new Date());
    (d.head || d.body).appendChild(s);
    })();
    </script>
    <noscript>{{'Please enable JavaScript to view the comments.'|t}}</noscript>
{% endif %}

Comments posted using this Disqus form will be assigned to the current entry.

This code is based on Disqus universal embed code. I stripped away unnecessary comments, added Twig variables representing current entry, added title setting (otherwise Disqus thread would be called "Untitled") and enabled static translation for <noscript> message.

Disqus plugin #

If you want to use Disqus Single Sign-On functionality, use nystudio107 Disqus plugin.

SSO allows you to use Craft built-in user accounts for commenting - commenters don't need to sign in using Disqus authentification. Besides that, Disqus plugin also allows you to display comments counter in various parts of the page.

If your website does not use user accounts for visitors, i suggest using plugin-less solution.

Comments plugin #

What if Disqus is not your thing? If you need comments seamlessly integrated with your website, Comments plugin might be a solution for you.

This plugin does not rely on external service like Disqus. It stores comments in database and allows you to to manage all comment related matters from Craft control panel.

Comments plugin is surely more advanced solution than Disqus integrations, but it comes with a price - it costs 49$. There is also a fact to consider - due to being more complicated, Comments plugin can take bit longer to set up, configure and deploy.


TAGS:
#twig component
If you want to get latest updates on Craft CMS tutorials and components, follow me on Twitter or subscribe to RSS feed.
Quick links for this article:
Disqus Twig component on github gists
Articles on blog:
  • Frontend testing for Craft CMS websites with Codeception and Cypress
  • Building reactive Craft Commerce product page with Sprig plugin
  • Dynamically generated PDF attachments for Freeform submissions
  • Using template hooks in Craft CMS
  • Alpine JS modal component for Craft CMS
  • Using template UI elements to extend Craft CMS control panel
  • Matrix within a Matrix - possible solutions for Craft CMS
  • Universal email template for Craft CMS
  • Creating attributes table from entry fields in Craft CMS
  • Namespacing forms in Craft CMS
  • Creating map-based navigation for Craft CMS
  • Placeholder image macro for Craft CMS
  • Building AJAX contact form with Craft CMS
  • Using incognito field plugin for Craft CMS
  • Email footer creator made with Craft CMS
  • Infinite scrolling and lazy loading with Craft CMS
  • Using Javascript in Twig templates with Craft CMS
  • Twig templating tips and tricks for Craft CMS
  • Basic SEO functionality for Craft CMS
  • Working with dates in Craft CMS templates
  • Working with SVG images in Craft CMS templates
  • Responsive and lazy-loaded youtube videos with Craft CMS
  • Debugging and inspecting Twig templates in Craft CMS
  • Creating article excerpts with Twig component in Craft CMS
  • Adding favicons to Craft CMS website
  • Truncating text with Twig macros in Craft CMS
  • Universal language switcher for Craft CMS
  • Read time macro for Craft CMS
  • Using attr() function to render HTML attributes in Craft CMS
  • Building dynamic, AJAX based pagination for Craft CMS
  • How to add Disqus comments to Craft CMS website
  • Ellipsis pagination component for Craft CMS
  • Converting email addresses into links using Twig macro
  • Breadcrumb created from URL for Craft CMS
  • Best developer-oriented Craft CMS plugins
  • Search autocomplete component for Craft CMS
  • RSS feed - template component for Craft CMS
  • Testing emails sent by Craft CMS using Mailtrap
  • Quick edit link - Twig component for Craft CMS
  • Filtering entries in control panel using Searchit plugin
  • Fetching routes into Twig templates in Craft CMS


Frontend testing for Craft CMS websites with Codeception and Cypress

Building reactive Craft Commerce product page with Sprig plugin

Dynamically generated PDF attachments for Freeform submissions

Using template hooks in Craft CMS

Alpine JS modal component for Craft CMS

Using template UI elements to extend Craft CMS control panel

Matrix within a Matrix - possible solutions for Craft CMS

Universal email template for Craft CMS

Copyright ©2023 Piotr Pogorzelski