Wrapping a Disqus implementation in a Roots-based WordPress theme

The Disqus filter is incredibly easy to get set up on your blog but it doesn't seem to provide a wrapper method for you to add your extra mark-up. This tutorial teaches you how to integrate it into your Roots-based theme.

Installing and setting up the disqus theme cleanly and succinctly takes over your vanilla flavour WordPress comments system but then I was left with a rather basic transition from end of post to comments section.

(If you haven't installed Disqus on your blog yet then you are way, way off in the wrong location right now. Visit http://www.disqus.com/ and the setup process is detailed their very clearly).

The content-single.php file in ./templates/ folder of your Roots theme has a call to the normal WordPress comments:

<?php comments_template('/templates/comments.php'); ?>

Normally you would be able to edit this file and change the html markup to provide your snazzy marketing phrases that engage the audience. When Disqus takes over however it adds a filter which basically wipes out the content generated in your comments_template() call and replaces it with its own.

I wanted to at least add a header to split if off but a container that I could style and an intro paragraph wouldn't hurt either.

After digging around for some kind of wrapper filter that I could use to override Disqus' override I eventually fell back to this solution:

<?php if (comments_open()) : ?>
<aside class="commentswrapper">
    <p>Make all the comments!</p>
    <?php comments_template('/templates/comments.php'); ?>
<?php endif; ?>

It checks if this post supports comments and then wraps the comments_template() call which Disqus then trashes anyway, but they don't get their hands on your modifications.

The comments_open() check is normally done in the comments.php but this way when your comments are disabled (which can be done by the user) you don't end up with a block something like:

Intro text
(complete lack of Disqus)


Scott said...

Thanks... it worked! Now... can I go back and return to "disable" access once I have the blog set up on WLW?

rtpHarry said...

No you have to keep it on that setting.

Koes Riantono said...

thanks brother :D

jorge clavellina said...

Thanks! you are the first one who tackle this specific issue!

mixture potlam said...

thanks dude.. I got the same problem. and now I cleared it out. because of you..... thanx a lot

Barbara Ford said...

Yes, WLW 2012. I am seeing comments from other WLW to blogger users about the same thing, so I don't think anything has gotten corrupted. I believe google has done something (yet again) with their security. They really don't want Microsoft products being used to post to blogger. Extremely frustrating. I would really consider totally switching away from blogger to another blog hosting, if I could figure out how to do it without losing all my years of work. I'm not thrilled with either Microsoft OR Google, but here I am, stuck in the middle.