WordPress.org

Ready to get started?Download WordPress

Forums

Using different comment system? (6 posts)

  1. futurepocket
    Member
    Posted 2 years ago #

    I am currently using Disqus on my blog.. I wanted to know how I could configure this on a page to page basis.

    I want my whole blog to use Disqus except for a group of pages to use the default WordPress comment system. Is this possible? Thanks.

  2. zimmi88
    Member
    Posted 2 years ago #

    For Disqus particularly? Hmm... I don't know if this is possible. I believe the Disqus plugin hooks in to the comments_template() template tag and overrides WP's default implementation with its own.

    You could try coding something into your theme to use comment function calls in the page.php template without calling comments_template()... might work, but I dunno. Something that says if within a set of page IDs use the custom solution, otherwise use comments_template().

    I hope this helps!

  3. futurepocket
    Member
    Posted 2 years ago #

    Could you perhaps elaborate a little bit? How do I set the "custom solution" to be WordPress' default comment system?

  4. Actually, it turns out to be really easy to do that.

    The Disqus plugin works by adding a filter like so:

    add_filter('comments_template', 'dsq_comments_template');

    So you hook into something before the comments_template like the_content and remove that filter but only for a specific post or page ID (IDs are unique). So if you wanted to use Disqus for everything but disable it for page ID 123 it's just

    add_filter( 'the_content' , 'mh_disable_disqus' );
    function mh_disable_disqus( $content ) {
       $id = get_the_ID();
       if( $id == 123 ) {
          remove_filter('comments_template', 'dsq_comments_template');
       }
       return $content;
    }

    You can use other tests instead of the ID such as has_tag( 'No Disqus' ) to handle Disqus commenting or not.

  5. futurepocket
    Member
    Posted 2 years ago #

    Do I just add that code into my functions? Don't I have to call it in my page/post.php files?

    "So you hook into something before the comments_template like the_content and remove that filter but only for a specific post or page ID (IDs are unique)."

    Sorry, I'm more of a PHP noob, how would I hook into that?

  6. Sorry, I'm more of a PHP noob, how would I hook into that?

    See that line that has add_filter? That hooks into the WordPress loop when the post or page content is being processed via the_content filter.

    There are lots of places to do that hook, I just picked it because the_content get's displayed before the comment_template. It's a good place to remove any filters or functions that effect the comment section for that post or page.

    You can put that code in your theme's functions.php file or create it as a plugin like so.

    http://pastebin.com/67raZpim

    Copy that text into wp-content/plugins/selectively-disable-disqus.php and activate it in your dashboard.

    Using it as a plugin is safer. If something goes wrong, just delete the plugin file.

    You will need to know what the ID of the page or post that you want to exclude Disqus comments from is. It's probably not 123. ;)

Topic Closed

This topic has been closed to new replies.

About this Topic