Search code examples
wordpressfiltercomments

How do I hide the WordPress comments form?


I have a plugin that enables Facebook commenting on WordPress. Users have requested a feature that will hide the default WordPress comments form on posts where Facebook commenting is enabled.

How do I go about hiding the WP comments form on the fly? I know I can comment out comment_form(); from the comments.php template, but I'd like to be able to hide/unhide it at the click on a button.

Does it have something to do with the comments_template filter?

The plugin's homepage is http://grahamswan.com/facebook-comments


Solution

  • Wrap the form in a div and use this simple piece of jquery to show/hide the div.

    <div class="comments">
    <?php comment_form(); ?>
    </div>
    
    <a class="comment_switch">Show / Hide Comments</a>
    
    .hidden{display:none;}
    
    $("comment_switch").click(function () {
         $("comments").toggleClass("hidden")");
       });