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.

By default "Discussion: Allow comments." is checked when a new page or post is created. I know you can make "Discussion: Allow comments." unchecked by default on both pages and posts by going to "Discussion Settings" and unchecking "Allow people to post comments on new articles".

I would like the default to be:

  • On posts: Discussion: Allow comments. (checked by default)
  • On pages: Discussion: Allow comments. (unchecked by default)

I do not want to use a plugin and don't want to modify the main WordPress code. I was hoping I could make a function in my functions.php file to do this?

Something like:

function disable_comments_on_pages() {

}
add_filter( '', 'disable_comments_on_pages' );
share|improve this question
1  
This is something that should be done in a plugin and not in a theme (you will probably want the functionality to remain after theme switch), And unless you have many pages it will probably be faster and easier to turn comments off per page (your question implies they might be on for some pages) then to write code to have a separate default for pages. –  Mark Kaplun Dec 29 '12 at 6:59
add comment

1 Answer

Hook into wp_insert_post, check if it is an auto-draft for a page, and set the comment_status to closed:

add_action( 'wp_insert_post', 't5_disable_default_comments_on_pages', 10, 2 );

function t5_disable_default_comments_on_pages( $post_ID, $post )
{
    remove_filter( current_filter(), __FUNCTION__ );

    if ( 'auto-draft' !== $post->post_status or 'page' !== $post->post_type )
        return;

    $post->comment_status = 'closed';

    wp_update_post( $post );
}
share|improve this answer
add comment

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.