WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
setting comments off as default for pages and custom post types?

When I create a new page, I want these two checkboxes (from the "Discussion" meta box) to appear unchecked by default.

Can this be done programmatically?

"Discussion" meta box

share|improve this question

marked as duplicate by kaiser, toscho Oct 9 '12 at 18:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

I'm assuming you already figured that turning off comments on the setting page won't work for your case? – developdaly Apr 5 '12 at 23:25
No. They should appear unchecked for the "page" post type only – onetrickpony Apr 5 '12 at 23:26
up vote 2 down vote accepted

You can re-register the "page" post type and leave out the comments capability.

add_action( 'init', 'my_new_page_type' );

function my_new_page_type() {
    register_post_type( 'page', array(
        'labels' => array(
            'name_admin_bar' => _x( 'Page', 'add new on admin bar' ),
        'public' => true,
        'publicly_queryable' => false,
        '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
        '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
        'capability_type' => 'page',
        'map_meta_cap' => true,
        'hierarchical' => true,
        'rewrite' => false,
        'query_var' => false,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'revisions' ),
    ) );

Actual answer: original source here

function default_comments_off( $data ) {
    if( $data['post_type'] == 'page' && $data['post_status'] == 'auto-draft' ) {
        $data['comment_status'] = 0;
        $data['ping_status'] = 0;

    return $data;
add_filter( 'wp_insert_post_data', 'default_comments_off' );
share|improve this answer
You'll still probably want to manually deactivate comments for all existing pages first. – developdaly Apr 5 '12 at 23:32
Didn't try it yet, but won't that completely disable the ability to comment? – onetrickpony Apr 5 '12 at 23:34
Yeah, I figured that was the goal, but now I see that you simply just want it to default off with the option to turn them on. Not sure about that one yet. – developdaly Apr 5 '12 at 23:35
Here we go: wordpress.stackexchange.com/a/2082/3293 – developdaly Apr 5 '12 at 23:36
That solution seems to work, thanks! You should update your answer or vote to close this Q as dupe – onetrickpony Apr 5 '12 at 23:44

Re-registering the page post type is a bit excessive. remove_post_type_support is a bit easier. Combined with the answer mentioned by @developdaly, and you'll effectively turn comments off.

add_action( 'init', 'wpse48145_remove_comments', 99 );
 * Removes support for comments from Pages.
 * @uses remove_post_type_support
function wpse48145_remove_comments()
    remove_post_type_support( 'page', 'comments' );
share|improve this answer
I think this should be the 'correct answer' - a lot neater. – Stephen Harris Apr 6 '12 at 8:29
@StephenHarris No one read the question! :D (And I even upvoted them!). – kaiser Oct 9 '12 at 18:56
I fairly certain the question changed since I posted this answer? – chrisguitarguy Oct 9 '12 at 20:02

This has/had annoyed me for a while so I did some digging around:

function wpse48145_unchecked_page_discussion () {
      if( 'page' == $_REQUEST[ 'post_type' ]  ) {
        add_filter( 'pre_option_default_comment_status', 'wpse48145_unchecked_page_discussion_filter' );
        // & if you want...
        add_filter( 'pre_option_default_ping_status', 'wpse48145_unchecked_page_discussion_filter' );
add_action( 'load-post-new.php', 'wpse48145_unchecked_page_discussion' );

function wpse48145_unchecked_page_discussion_filter ( $val ) {
    return 'closed';

works as of WP 3.4.2

share|improve this answer
+1 But please use get_post_type() instead of $_REQUEST['post_type']. Also: You don't have to state the priority and var number on add_filter/*_action calls when it's only one argument. – kaiser Oct 9 '12 at 12:24
get_post_type() is not available by that time. I just followed the methodology in wp-admin/admin.php where the load-{page} action is triggered. – Dankicity Oct 9 '12 at 18:14
$_POST doesn't work there, only $_REQUEST or more appropriately, $_GET. Tried to test get_post_type even with passing globals and no dice.. looks like $_REQUEST/$_GET is the only way... – userabuser Oct 9 '12 at 18:49
@userabuser Thanks! – kaiser Oct 9 '12 at 18:50
I now added the solution to the trac ticket, that @ChipBennet posted. – kaiser Oct 9 '12 at 18:56
  1. Go to Dashboard -> Settings -> Discussion
  2. Find Default Article settings
  3. Uncheck "Allow link notifications from other blogs (pingbacks and trackbacks)" and "Allow people to post comments on new articles"

These changes will not change settings for existing posts. If you want to change existing posts, do a Bulk Edit from the Dashboard -> Posts screen.


Sorry, I misread your question initially. WordPress doesn't provide a UI to set default comment status based on post type.

Note: this is a known issue.

share|improve this answer
This also affects posts. I only need it for pages – onetrickpony Apr 5 '12 at 23:25
Sorry; misread your post. See update, and linked Trac bug report. – Chip Bennett Apr 5 '12 at 23:58

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