Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want my pages to not have comments enabled by default, only my posts. Is this possible?

share|improve this question
1  
    
@toscho An interesting idea - should be an answer instead. –  kaiser Aug 27 '12 at 10:46
    
@kaiser I did that. Two times. –  toscho Aug 27 '12 at 14:42
    
@toscho In this case, just tell me where to move my answers and then close this question. –  kaiser Aug 27 '12 at 16:27
    
The other questions are either bad or not a duplicate. We leave it as it is for now. –  toscho Aug 27 '12 at 16:28

3 Answers 3

The Front-End Solution:

Trick your templates

You could fake that comments are open for specific post types. The following code works for all templates, that wrap the comment form (or whatever comment related code/UI elements) inside a conditional comments_open() check.

The little magic

… wrapped up in a quick'n'small plugin.

/**
 * Plugin Name: Disable comments for post types
 * Author: Kaiser
 * Author URl: http://unserkaiser.com
 */

/**
 * Set comments open to FALSE for specific post types
 * 
 * @param  bool $open
 * @param  int  $post_id
 * @return bool $open
 */
wpse63098_diable_comments( $open, $post_id )
{
    if ( ! $open )
        return $open;

    $curr_post = get_post( $post_id );
    if ( in_array(
         $curr_post->post_type
        ,array(
            'page'
            // Add other (custom) post types here
         )
    ) )
        return FALSE;

    return $open;
}
add_filter( 'comments_open', 'wpse63098_diable_comments' );

How to use it

Just upload and enable the plugin in the administration. Now every time the template questions for something like…

if ( comments_open() )
{
    // show comment form or whatever
}

…the comment_open() function gets intercepted and spits out a FALSE for your post type (like for example pages). Then it simply skips whatever is wrapped in there and doesn't show comments.

share|improve this answer

The Back-End Solution:


Javascript to set the default to unchecked

When you got the "Discussion" Meta Box open, then both checkboxes (Comments & Pingbacks) will be set to the value from…

Admin UI » Settings » Discussion » Discussion Settings » Default article settings » "All people to post comments on new articles"

A plugin to change the defaults

As we can't simply set different values for different post types, we can rely on javascript (which won't work, if JS is turned off - for example in a screen reader).

Now the meta box offers a hook, where we can add this little javascript snippets.

 <?php
 /**
 * Plugin Name: Uncheck comments for post types
 * Author: Kaiser
 * Author URl: http://unserkaiser.com
 */

/**
 * Uncheck ping/comments open status checkboxes for specific post types
 * 
 * @param  object $post
 * @return void
 */

function wpse63098_disable_comments_cb( $post )
{
    if ( ! in_array( 
         $post->post_type
        ,array(
            'page'
            // Add other (custom) post types here
         )
    ))
        return;
    ?>
    <script type="text/javascript">
    jQuery( document ).ready( function($) )
    {
        // Comments
        if ( $( '#comment_status' ).is( ':checked' ) )
            $( '#comment_status' ).attr( 'checked', false );

        // Pings
        if ( $( '#ping_status' ).is( ':checked' ) )
            $( '#ping_status' ).attr( 'checked', false );
    }
    </script>
    <?php
}
add_action( 'post_comment_status_meta_box-options', 'wpse63098_disable_comments_cb' );
share|improve this answer
    
Interesting idea, but doesn't seem to work (I added an extra ')') so it would compile. I also added a <script> tag around the Javascript –  Casebash Aug 27 '12 at 5:46
    
@Casebash Added the script tags (thanks). Will test later and get back to you. –  kaiser Aug 27 '12 at 10:44

You probably just need to show the widget for Discussion.

enter image description here

1 go to Edit a Page and
2 select the Screen Options.
3 Check the Discussions box
4. Close / hide screen options. 5. Scroll down you page and you'll see the new Discussion widget 6. uncheck Allow Comments

[edit ... i was going to show another image here ... but suddenly the upload failed]

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.