I want to turn the comments off by default with pages and custom post-types
Initially I simply used conditionals in the comments display function to avoid displaying the block on these pages, but I need the user to be able to turn the comments back on as required.
From what I understand, you want to set pages and some custom post types to have commenting ‘off’ by default, while posts will still use the default option (i.e. commenting ‘on’). If this is the case, the following function will do it.
When you create a new post(custom type or regular), WordPress calls
get_default_post_to_edit
which then sets the default values a new post will have.This function provides a few filter hooks for changing the default title, content and excerpt, but unfortunately nothing else… however each filter passes along the complete
$post
object to the callback, essentially this means it’s possible to redefine several properties(or just one if we like)This should work for you, simply add the post types the code should apply to as cases inside the switch.. (movie and page are examples)..
Code was tested on WP 3.0.1 and has the desired effect of disabling comments for the post types specifically whilst leaving others to inherit default status from the
default_comment_status
option.Hope that helps…. 🙂
I’ve written a plugin to disable comments on pages by default.
http://wordpress.org/extend/plugins/page-comments-off-please/
Perhaps that will help?
I’d recommend still using your conditionals in the comments display, but use options to store your conditional settings. Then you can add a page to the Settings menu that allows administrators to turn comments on or off as needed.
Update
It occurs to me that you want to set the default for commenting to “off” as a global setting rather than setting it to “off” each time you create a page. This is possible.
Go to Settings >> Discussion in the WordPress admin section. In the first section (“Default Article Settings” you’ll see an option called “Allow people to post comments on new articles” … uncheck this option.
Now, by default, comments will be turned “off” for all new posts, pages, and custom post types. You can still turn comments back “on” on a case-by-case basis by selecting the appropriate checkbox in the “Discussion” meta box on the individual post/page edit screen.
According to this thread, what you’re requesting isn’t possible without the use of a custom plugin or function to accomplish it.
Slightly more elegant way to do this in 2022:
That disables all comment types (comments and pingbacks/trackbacks) on new media library attachments. You can obviously change the post type to whatever you want, or you can include the third parameter in the
get_default_comment_status
filter to affect only a specific comment type.If you simply add this code in functions.php
Go to the post, and in the screen options, tick on “Discussion” and “Comments”, you can enable/disable comments for each custom post type.