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 already know how to remove a metabox from my custom post type edit page. However I want to remove the comments metabox but still allow commenting for the post. Because I notice when I do remove it, it disables comments. Any function I can use?

share|improve this question
add comment

4 Answers

up vote 0 down vote accepted

Dont remove this via CSS, the _POST part is also active and WP save the date! Use the custom function for remove meta boxes; code by scratch

function fb_remove_comments_meta_boxes() {
    remove_meta_box( 'commentstatusdiv', 'post', 'normal' );
    remove_meta_box( 'commentstatusdiv', 'page', 'normal' );
    // remove trackbacks
    remove_meta_box( 'trackbacksdiv', 'post', 'normal' );
    remove_meta_box( 'trackbacksdiv', 'page', 'normal' );
}
add_action( 'admin_init', 'remove_comments' );

see more on a plugin to remove all UI-elemts and function for comments: https://github.com/bueltge/Remove-Comments-Absolutely

share|improve this answer
add comment

You can use the UI to remove it:

Click on the "Screen Options" at the top right side of the edit screen

enter image description here

and uncheck the Discussion check box

enter image description here

or if you want to do it by code simply hide the container div by style="display:none;"

function hide_comments_div() {
global $pagenow;
if ($pagenow=='post-new.php' OR $pagenow=='post.php')
        echo '<style>#commentstatusdiv{ display:none; }</style>';
}
add_action('admin_head', 'hide_comments_div');
share|improve this answer
    
problem with this is that it doesn't remove it completely. if you pull down the screen options you can recheck it and then it displays again. I'm looking more for a way to force the comments to be allowed while I remove that metabox through the 'supports' option in the custom post type. –  JonnyPlow Oct 5 '11 at 19:00
    
If you remove the comments through the 'supports' option in the custom post type you remove the comments all together. you can try using remove_meta_box( 'commentstatusdiv' , 'page' , 'normal' ); –  Bainternet Oct 5 '11 at 19:08
add comment

There is problem in file /wp-includes/post.php function wp_insert_post()

if ( empty($comment_status) ) {
 if ( $update )
  $comment_status = 'closed';
 else
   $comment_status = get_option('default_comment_status');
}

Your comments will be close after update. The solution is change callback of commentstatusdiv insted:

add_action(
 'add_meta_boxes', function () {
    global $wp_meta_boxes, $current_screen;
    $wp_meta_boxes[$current_screen->id]['normal']['core']['commentstatusdiv']['callback'] = function () {
        global $post;
        echo '<input type="hidden" value="' . $post->comment_status . '"      name="comment_status"/>';
        echo '<input type="hidden" value="' . $post->ping_status . '" name="ping_status"/>';
        echo '<style type="text/css">#commentstatusdiv {display: none;}</style>';
    };
  }
);
share|improve this answer
add comment

Add this in functions.php of your theme

function tune_admin_area() {
        echo '<style>#commentstatusdiv{ display:none; }</style>';
}
add_action('admin_head', 'tune_admin_area');
share|improve this answer
    
problem with this is that it doesn't remove it completely. if you pull down the screen options you can recheck it and then it displays again. I'm looking more for a way to force the comments to be allowed while I remove that metabox through the 'supports' option in the custom post type. –  JonnyPlow Oct 5 '11 at 18:59
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.