This past Friday, we had a customer calling in and telling us that he just integrated Disqus (the famous commenting platform) on his Joomla website, but for some reason, every time someone makes a comment on one page, it appears on all the other pages. In other words, all the Disqus comments for that website were being displayed on all pages. That website is in the top 10,000 websites in the world so you can imagine how much frustration this issue was causing (for both our customer and the site’s visitors). Needless to say, the issue had to be fixed – and had to be fixed fast!
We looked at the website and we immediately located the problem, the problem was happening because the JavaScript Disqus variables were the same on every page: every article had those same JavaScript values on every page:
var disqus_url = 'http://ourclientwebsite.com'; var disqus_identifier = '1234567890';
Disqus is clear in its documentation that the above values must be different on every page for the comments to appear properly.
So, what did we do to solve the problem?
The first step towards solving the problem was knowing which plugin was responsible for generating the Disqus code, and it wasn’t really hard to find, it was the Disqus Comments for Joomla! by JoomlaWorks. The code responsible for generating the Disqus code was in the file jw_disqus /plugins/content/jw_disqus/ folder. So, we opened up that file, and we changed the following 2 lines:
var disqus_url = '".$output->itemURL."'; var disqus_identifier = '".substr(md5($disqusSubDomain), 0, 10)."_id".$row->id."';
to:
var disqus_url = '".JURI::current()."'; var disqus_identifier = '".substr(md5($disqusSubDomain), 0, 10)."_id".md5(JURI::current())."';
That fixed the problem, but, shortly after, we discovered that there was another problem! Because the site allowed for URL duplication (this means that a page can have multiple URLs), which can be regarded as a feature or as an issue (we think it’s the latter because of the SEO implications), the above code did not work properly, because it is displaying the comments per URL, and not per page (this is because we’re using JURI::current() as the disqus_url), so, if someone makes a comment on a page, then the comment will only display on the URL that it was made on, and not on all the URLs pointing to that page (yes, we know, this is very confusing). It was a serious problem and we needed to resolve it.
So, how did we address the URL duplication issue?
Luckily, every URL on the site had the ID of the article it was pointing to in its last part, so, all we needed to do was to extract the ID from the URL, and create a fake but unique URL for every page, such as, http://ourclientwebsite/12345, where 12345 is the ID of the article. In order to do that, we added the following code to the jw_disqus.php file (the content plugin) just after line 201 ($output->disqusIdentifier…):
$arrCurrentURL = explode('/', JURI::current()); $lastCurrentURL = (int)$arrCurrentURL[count($arrCurrentURL) - 1]; if (!empty($lastCurrentURL)) $strCurrentURL = JURI::root().$lastCurrentURL; else $strCurrentURL = JURI::current(); $strCurrentURLHash = substr(md5($disqusSubDomain), 0, 10)."_id".md5($strCurrentURL);
We then changed the Disqus URL and identifier lines to the following:
var disqus_url = '".$strCurrentURL."'; var disqus_identifier = '".$strCurrentURLHash."';
We uploaded the file back and the issue was resolved!
If you have a problem with Disqus integration on your website, then please contact us. We are always an email or a call away, we don’t charge much, and you can rest assured that we will solve your problem in no time!