27.9.2011

WP: Turn Off Comments / Ping Backs by Default from Pages

Turn Off Comments / Ping Backs by Default from Pages

Themes functions.php or yourplugin.php:

// This is valid hack as long as "wp-admin/includes/post.php"  
// `get_default_post_to_edit()` keeps calling `apply_filter()` for   
// `default_content` *after* `comment_status` and `ping_status` setting.
function my_disable_pages_default_commenting($content, $post) {  
    if ($post->post_type == 'page') {  
        $post->comment_status = "closed";  
        $post->ping_status = "closed";  
    }  
  
    return $content;  
}  
add_filter('default_content', 'my_disable_pages_default_commenting', 1, 2);

Snippet above turns off the check boxes only from New Pages, any existing pages must be unchecked manually.

← Back to blog