Wednesday, 08 April 2015 19:01

How to add Disqus (comment integration) into Joomla+K2

Written by 
How to add Disqus (comment integration) into Joomla+K2

Before we begin, yes, K2 does have its own, built-in comment functionality.  And yes, there are plugins already built and available for this.  The reason I like this solution is twofold:

  1. K2's comment functionality, while has many useful features (Captcha anti-spam, email notifications, admin approval process), people seem to like using Disqus because it supports logins from multiple accounts (Disqus, Facebook, Google, Twitter).  K2's inbuilt commenting feature can be set up to allow comments from anonymous visitors, which opens up your site to comment spam.
  2. I don't like installing an entire plugin just to accomplish one little thing.  While I'm sure the plugin works, you have more customization / control when you handle the actual code.  This is similar to the plugins that allow you to add Google Analytics to your site - maybe it's just a pet peeve of mine - but I'd rather edit a (single, easy) file than install a new extension, which is a potential security risk.

Let's get started, shall we?  

Below are a few files you'll need.  

    This file contains a code snippet that you'll need to add to your site template's "index.php" file.  This can sometimes be accomplished by going into Extensions -> Template Manager, and using one of the template parameters to inject the code (assuming your template has this feature).  Or, you can go into the actual template's index.php file using FTP and change it directly:  /your_site/templates/your_template/index.php
    In the code, you'll see a reference to a "forum shortname" which comes from your Disqus account; you'll need to change my text that says "CHANGE_THIS" to your actual shortname.
    This will extract and give you a folder labelled "disqus" - it is a K2 template override, which means if you're using overrides properly, it will go here: /your_site/templates/your_template/html/com_k2/
    Otherwise, the standard location for K2 templates is here: /your_site/components/com_k2/templates
    The standard K2 template folder will be called "default" - I suggest adding the "disqus" folder alongside the default folder so that you can use the K2 category parameters to indicate which sections of your site use comments and which ones do not.

Inside the disqus ( folder, there are only two files that you need to pay attention to:

  • item.php (lines 98-106, and lines 691-703)
    In the code (line 691), you'll see a reference to a "forum shortname" which comes from your Disqus account; you'll need to change my text that says "CHANGE_THIS" to your actual shortname.
  • category_item.php (lines 122-124)
Read 12045 times Last modified on Wednesday, 08 April 2015 19:38


  • Comment Link Nate Covington Friday, 10 April 2015 18:17 posted by Nate Covington

    Excellent points, thank you. I use sh404sef so the non-sef-page item should be a non-issue? And no, I am not using Disqus on my own site because I prefer to host all of my data.

  • Comment Link Ashwin Friday, 10 April 2015 18:09 posted by Ashwin

    It's ironic that this site does not use disqus comments ;)

    Also you left 1 important thing. Apart from short name you must add the disqus identifier otherwise your sef and non-sef pages will show a different set of comments. By default disqus uses the url to store and fetch comments against. Specifying the disqus id as the k2 item id will overcome this.

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.