Hacking Disqus
08 April 2008 – 4:13 pmNo video for this post today. It’s just pure geekery that just cannot be made any less geeky or any more interesting by staring at my talking head.
Have I mentioned before that I <3 Disqus? I think maybe I have.
And a big thanks to the disqus guys for adding in a quick feature request I had that allowed me to pull my own disqus comments from every blog into my lifestream here on my homepage.
There are some other features that I’d like to see, and to work that out on my own, I’ve been doing some hacking and tweaking to get Disqus to do exactly what I want in Wordpress. Here’s what I’ve done so far and how you can implement it on your own.
If you do make these changes, keep a few things in mind:
- I did this in the beta version of the wordpress plugin.
- once they issue an update, these changes will be overwritten and if they haven’t addressed them, will need to be redone. That’s the life of a gangsta.
- proceed at your own risk.
Trackbacks
Disqus doesn’t have any support at all for trackbacks. But since Wordpress will still grab and store them in your comment database, you can still display those. Add the following code somewhere in your wp-plugins/disqus/comments.php script. Be sure to edit the one in the plugin dir. I put mine way down at the bottom.
<h3>Trackbacks</h3>
<ol>
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link() ?></li>
<?php } ?>
<?php endforeach; ?>
</ol>
DoFollow/NoFollow
Disqus posts all links in comments as dofollow links. (sans the rel=”nofollow”). That’s not that bad since Disqus has measures to prevent spammers. But it doesn’t stop the comment monkeys.
So I’ve been playing with a few different ways do put nofollow on some of the spammier comments while taking the opportunity to give dofollow back to the good guys.
Here’s what I did, again to comments.php. The bold code is what I added, I’ve included a little context so you can put it in yourself:
<ul id="dsq-comments">
<?php foreach ( $disqus_response['posts'] as $comment ) : ?>
<?php
//SCJ added check for rel=nofollow
if ($comment['points'] < 1 || $comment['user']['is_anonymous']) {
$follow = ‘ rel=”nofollow” ‘;
} else {
$follow = “”;
}
//SCJ end change
$profile_url = DISQUS_URL . ‘/people/’ . $comment['user']['profile'] . ‘/’;
?>
That sets the $follow var which I just slip into the website link here, down about 30 lines from the first change.
<?php if ( $comment['user']['url'] ) : ?>
<li><a href=”<?php echo $comment['user']['url']; ?>”
target=”_blank” <?php echo $follow?>>Website</a></li>
<?php endif ; ?>
Feature Requests for Disqus
While I’m at it, here are some feature requests…
- Incorporate real trackback support. I don’t think I care whether you just use Wordpresses trackback support like I did or try to incorporate it into your service. If you think you can do something about the spammers and scrapers, then by all means take it in. Maybe just allow an option to show trackbacks above or below the comments?
- Do something with the Dofollow/Nofollow. I’m pretty happy with the rules I set, which is to add in a nofollow for anonymous commenters and for comments that have been voted down. But something more sophisticated could surely be done and would be welcomed here.
- I want more notifications on blogs that I comment on. Right now, I think you send me an email if someone replies to one of my comments somewhere. But if there’s a conversation going on in a blog post that I’ve commented on, I want to know about it. Can I opt to get notified of any reply in a blog post that I’ve contributed to?
- I want to do more with Disqus, namely allow people who read my blog to START conversations, not just respond to the ones I start. I sent you guys at Disqus an email about this with more details. But I really think you guys are just scratching the surface here.
- I’m sure your lunches with Loic have you thinking about video comments, so I won’t waste a wish on that one.
What do you say, does anybody have other wishes? They’re hiring and surely need stuff for that Python hacker to do.
If you enjoyed this post, please subscribe to my RSS feed


I did enjoy this post, but unfortunately I am already a subscriber..... Boy that line really jumps at ya.... lol
Thanks Scott!
Great work, Scott. This will help out a ton of people!
1. Ok, ok. We'll support trackbacks. :)
2. I like that approach. We'll probably do something similar.
3. Definitely. Notifications is undergoing some tweaking right now.
4. I read your email thread this morning. On your community page, readers can most definitely create new conversation threads. Try it out and let me know if this is what you're looking for.
5. Videos!
Cheers Scott. Thanks for the feedback and GREAT hack.
Thanks for the quick reply, Daniel. A little more detail on #4 for you.
I want people to be able to start a new conversation from here by filling in a form on it's own page on jangro.com. I'm concerned that the hand-off wouldn't be smooth enough otherwise, unless you let me customize my community page more (there's request #6).
I could rip off your comment form, but I'm guessing that you detect the http_referer and all submissions will end up being a comment in a single thread.
I'm happy to let the ensuing conversation happen over at Disqus with the hopes that I'll be able to later integrate more deeply here with an API. For now, I just want to kick the conversation off here.
Gotcha. We'll take about this but this could be pretty interesting.
Re: "I could rip off your comment form"
You can override it by setting these variables right before the javascript code for the comment form:
var disqus_title = "Whatever You Want";
var disqus_url = "http://www.whateveryouwant.com";
You can then pull it back using the URL if you go to http://jangro.disqus.com/?url=http://www.jangro.com/a/2008/04/08/hacking-disqus/
Thanks for the info Paul, I'll play around with that.
Nice work with the Google Reader Disqus, btw.
ok paul, I don't think this is quite what I'm looking for.
I want people to be able to post a new topic, as if they started a new discussion directly on my jangro.disqus.com community, in a specific category, like this:
http://jangro.disqus.com/c/7868/new-thread/
There is no unique blog entry to attach each thread to.
Basically, I want to use the "forum" functionality that disqus has, but short-circuit it to my blog as a front end.
You can still do it...you have to copy this file to your local server and take out the following code:
if(disqus_message.length > 400) {
disqus_message = disqus_message.substring(0, disqus_message.indexOf(' ', 350));
}
The idea would be to have a form on a page with Title/Message/Category - when that form is submitted it would pull up another page with this code:
<script>
var disqus_title = <?php $_GET['title'];
var disqus_message = <?php $_GET['message']; ?>
<?php
if($_GET['catid'] == "Affiliate Marketing") {
$catid = "7866";
} elseif($_GET['catid'] == "Web 2.0 Goodness") {
$catid = "7867";
} elseif($_GET['catid'] == "DLP TV Repair") {
$catid = "7868";
} else {
$catid = "6132";
}
?>
disqus_category_id = '<?php $catid; ?>
var disqus_url = "";
</script>
<div id="disqus_thread"></div><script type="text/javascript" src="http://www.jangro.com/....../embed.js"></script>
Excellent Paul. Clearly you've been spending some serious quality time with the Disqus Javascript. Thanks for sharing what you've learned. It's a big help.
I just tried that code...I think you might have a big hurdle because you don't know the Disqus user that is logged in.
It would almost have to be a two-step process - Type a title/Choose a category and take them to the page where they put in a comment....which would almost be better because otherwise you would lose the comment-tracking features if they were just "creating" a thread (FriendFeed, any followers through Disqus).
I totally see what you're saying Paul. A unique URL based on the title in the query string creates the page in which the discussion can be held.
That gives disqus a url to link back to as well where the discussion could continue on the blog.
All of this is leading me toward a solution where I just set up a database table to capture the initial question/post which serves as the unique page, and let disqus handle the comments.
Daniel,
Since you are following this thread I though I would jump in with my own request...
The only reason I did not allow Disqus to manage comments on every single posts on my blog was because it would hide the exiting comments. I would like to see a feature that would import the exiting comments into Disqus unless of course there is away to show existent comments.
Hi Vlad,
We're definitely working on data migration still. It's difficult to get right but we won't ignore it.
Daniel,
It's good to know you are working on it. :) I would love to let Disqus to
manage ALL the comments.
Disqus is like a new toy that is fun initially, but eventually becomes more of a liability and shoved to the back of the closet. Hopefully it won't be too hard for you to re-import your comments back into the WP database.
Wow, Peter, I didn't know you were such a cynic. :)
I am definitely one to dabble with new toys, but in this case I'm going to disagree with you. I take blog comments very, very seriously and didn't jump into this one lightly.
Sure there are some risks here like the trouble of importing, but I think the opportunity for this to take conversations and blogs to another level far outweighs them.
The "fun" wearing off is, to me, not even a risk. Worst case, even if boredom completely sets in, it's no worse than regular old blog comments.
But the potential upside is so much more.
LoL, yea it's been a rough week. Google updates make me nervous... I need to get out on the golf course or something, you up for a round?
But, there is a basis for my skepticism, I did go through a period where I wanted to add every addon, new feature and hack to my sites. Then, when upgrade time comes along it becomes a bit more work, and with each successive round of upgrades this or that becomes incompatible and a bigger headache. So I'm in more of a 'keep it simple' state of mind now.
Definitely up for a round. any time!
Anyone else? :)
Scott,
I just noticed that with your trakcback hack, the links are "nofollowed". If it was me, I would rather have my comments "noffolowed" but give credit to legitimate pingbacks. Can I remove the "nofollows" from trackbacks?
That's just wordpress putting nofollows on all comments, though you're only using wordpress for the comments that are trackbacks. They're treated just like comments in WP.
If you turn on the dofollow plugin that should take care of it.
I do have Lucia's Linky Love turned on. Correct me if I am wrong, the "dofollow" plugins generally affect only what is in the "commnets.php". I think the dofollow pluing should be modified so it is working with Disqus' comments.php.... unless of course I remove the nofollow in the core files.
I'm not sure, Vlad. The code in both in the core comments.php and what we pasted into Disqus' comments.php calls a WP function to get the link: comment_author_link().
I figured that the dofollow plugins hook in at that level, and if so, it should work the same way.
I am guessing it's the Dofollow plugin that is at fault.... On the other hand I was just thinking... When you show a track back on your blog, in a way it becomes a "link exchange" event with the website that just linked to you. Am I off the mark here?
You could call it a link exchange event. Though if you're bringing along with that the associated stigma with link exchanges where they are harmful to SEO, I don't think that's the case.
Trackbacks are sort of accepted link exchanges. I'd guess that at the worst they're discounted, but not penalized.
Thanks for setting me straight on this one ;).
Thanks for the Trackback Hack. It will serve its purpose until that feature is added to Disqus proper.
I just added your trackback code. Good stuff, thanks!
Thanks for the referral!
Glad to be helpful, Shey. Looking forward to seeing Disqus on your blog!
thanks for the tip!
Indeed, this article is a great help.
1. Trackback is a must have
2. A simple but effective one