WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] turn off comments on pages by default (25 posts)

  1. Don Spark
    Member
    Posted 4 years ago #

    Hi,

    Simple question:

    How do I make comments "turned off" by default?

    I am shaping up a WP CMS for non-technical users. They shouldnt have to worry about erroneous check boxes.

    Thanks!

    Don Spark

  2. TransPersonal
    Member
    Posted 4 years ago #

    Settings >> Discussion >> uncheck "Allow people to post comments on new articles"

    This applies to new posts that you will publish from now on. To disallow comments from already publish posts:

    Posts >> select them all and "Edit" under bulk actions and hit apply >> choose "do not allow" next to comments and hit update posts.

  3. @mercime
    Volunteer Moderator
    Posted 4 years ago #

    What TransPersonal said. And, if you want to make it pseudo-permanent, you can delete the comments tag in single.php (and in page.php if you have one there)from your theme.

  4. S.K
    Member
    Posted 4 years ago #

    The topic title talks about "pages". Assuming that you want to continue have discussion on your blog posts but turn it off only from "pages, you'll have to remove the code snippet "<?php comments_template(); ?>" from the page.php of your theme, as mercime advised.

    If your theme uses some other template for pages, you find it out and snip out the line.

    S.K

  5. Don Spark
    Member
    Posted 4 years ago #

    I just want to turn it off by default...on pages only. I want blog posts to have comments by default but not pages. The checkbox has a checked by default. I want it un-checked by default for pages.

    I am using the hybrid theme framework. That theme has a page.php which has this only this referring to comments
    <?php comments_template( '', true ); ?>

    Is something in there putting a check in the box or does that exist somewhere else in wordpress?

    We are going to be making lots of pages with nubies.

    Thanks!

  6. @mercime
    Volunteer Moderator
    Posted 4 years ago #

    If you want to have comments in your blog posts, then leave the comments on in Settings > Discussion. Then in order to disable comments in Pages, delete <?php comments_template( '', true ); ?> in page.php

  7. S.K
    Member
    Posted 4 years ago #

    You can remove that line of code if you want to disable comment on pages.

    Instead you can "comment out" the line of code thus:

    <?php// comments_template( '', true ); ?>

    You can remove the "//" part when you want to turn on comments on pages.

    HTH.

    S.K

  8. Don Spark
    Member
    Posted 4 years ago #

    Thanks guys.

    Anyone know how to make this default?

    un-check

    the comments check box

    on pages only

    I need to be able to turn it on sometimes with the check box.

  9. dou9las
    Member
    Posted 4 years ago #

    Well, I can't speak for Don, but I for one was just looking for the answer to this, and this thread was perfect. Kichu, Transpersonal, Mercime, thanks, you hit the issue spot on for me.

    I wanted to simply take the comments off all pages (indefinitely) while keeping them available on blog posts.

    In particular, thinking I was all saavy and smart, before finding this, I went into page.php and used the <!-- to comment out the entire php tag - but it broke the pages.

    I know that these different methods of commenting are used in slightly different ways, one for removing the instance of html (if I remember right) the other simply killing the php function. I don't fully comprehend the differences in application of those, but anyway, I am a step closer to that, and my site is now working as intended.

    Thank You!

  10. calanan
    Member
    Posted 4 years ago #

    Adding my word of thanks to kichu, et al as I was trying to do just that (disable the comments area on just pages) and had no clue as to how to do it. Cheers!

  11. grizzdesign
    Member
    Posted 4 years ago #

    I want the same thing done... Comments off by default on new pages.

    Reason being the RSS-feed being putted into wp_head().

    Deleteing the comments_template() doesn't uncheck the box in the page-editor and thus doesn't get rid of the RSS feeds on page for "comments".

    So, question remains:
    How can me make a setting that will automaticly disable comments for pages (and leave it on for comments) - OR - how can we get rid of the RSS-feeds for comments on PAGES.

    --
    Thanks in advance,
    gd

  12. joxie
    Member
    Posted 4 years ago #

    sounds like a lot of experts here on the topic of Comments on Pages.
    Can you offer assistance on a similar problem related to this topic?

    See http://wordpress.org/support/topic/338324

    Thanks!

  13. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    topic not found

  14. joxie
    Member
    Posted 4 years ago #

    not sure what that "topic not found" problem is about.

    try this re-post:
    http://wordpress.org/support/topic/338366?replies=2#post-1303350

  15. fob
    Member
    Posted 4 years ago #

    Too late?

    Using Hybrid I would suggest to use a function within your functions.php.

    First add an empty file your template folder (sub theme), nothing in. No code, nothing. Just give it a name like "no-comments-please.php" and upload it to your server.

    After that you can add something like this to your functions.php in order to call the file when pages are called:


    add_filter( 'comments_template', 'remove_comments_template_on_pages', 11 );

    function remove_comments_template_on_pages( $file ) {
    if ( is_page() )
    $file = STYLESHEETPATH . '/no-comments-please.php';
    return $file;
    }

    After that comments will be removed from all pages. If you like you can enhance the function to do whatever you want.

    Best regards and happy christmas
    Oliver

  16. joefletcher
    Member
    Posted 4 years ago #

    Hey Oliver, never too late. That's exactly what I need to do.

    But, does anyone know how to either uncheck "allow comments" & "trackbacks" in the ADMIN on Pages only? So that by default, Posts have it checked; Pages have it unchecked.

    Or, if I remove Comments from the Page templates as described above, then any suggestions on removing that Meta box for Comments - again, in the Admin for Pages only?

  17. Ryan
    Member
    Posted 4 years ago #

    Was looking for a solution for this, but didn't want to go the "all or nothing" approach outlined above. My solution is this:

    Step 1
    Create a new custom field called "allow_comments" and on any pages I want comments give that custom field a value (1, true, allow, whatever).

    Step 2
    Open up your theme's page.php and find the following line:
    <?php comments_template(); ?>
    Replace with:

    <?php $allow_comments = NULL; $allow_comments = get_post_meta($post->ID,'allow_comments', false); ?>
    <?php if ($allow_comments[0]) { comments_template(); } ?>

    This checks to see if the page has a value for the allow_comments custom field. If it does, it displays the comments.

    With this in place in the page.php file (and not in the single.php file), by default it will not display comments for pages. But by adding the allow_comments custom field with (any) value, the comments mechanism can be quickly enabled for any page.

    Hope that helps someone else.

  18. rshandel
    Member
    Posted 4 years ago #

    Thanks for all info. Unfortunately, my page is acting strangely. It seems my theme (lightword) already has provisions for adding comments on pages, BUT, when I add one comment it removes the "leave a comment box". I tried everything. I did a var_dump on the $post array and before I add a comment on a page, it contains all the data, has comment_status = open, etc.

    As soon as I add one comment on a page, the array is empty except some integer value i.e. int(19).

    the page.php code is

    <?php if (comments_open() && $lw_disable_comments == "false"):comments_template();endif;?>

    this executes fine, but $post array doesn't contain a comment_status value and thereby doesn't execute the condition in the comments.php to display comments form:

    here's the comments.php code:

    <?php
    if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
    die ('Please do not load this page directly. Thanks!');
    if ( post_password_required() ) {
    echo '<p class="nocomments">';
    echo _e('This post is password protected. Enter the password to view comments.','lightword');
    echo '</p>';
    return;
    }
    $comments_nr = fb_get_comment_type_count('comment');
    $trackbacks_nr = fb_get_comment_type_count('pings');
    $oddcomment = 'alt ';
    ?>
    <div id="tabsContainer">
    <a href="#" class="tabs selected"><span><?php _e('Comments','lightword'); ?> (<?php echo $comments_nr; ?>)</span></a>
    <a href="#" class="tabs"><span><?php _e('Trackbacks','lightword'); ?> (<?php echo $trackbacks_nr; ?>)</span></a>
    <span class="subscribe_comments"><?php post_comments_feed_link(__('( subscribe to comments on this post )','lightword')); ?></span>
    <div class="clear_tab"></div>
    <div class="tab-content selected">
    <a name="comments"></a>
    
    <?php if ( $comments ) : ?>
    comments<br />
    <div id="comentarii">
    <ol class="commentlist">
    <?php wp_list_comments('type=comment&callback=nested_comments'); ?>
    </ol>
    
    <?php if ((int) get_option('page_comments') === 1 && get_comment_pages_count() > 1): ?>
    comments<br />
    <div class="next_previous_links_comments">
    <span class="alignleft"><?php previous_comments_link(__('&laquo; Older Comments','lightword')); ?></span>
    <span class="alignright"><?php next_comments_link(__('Newer Comments &raquo;','lightword')); ?></span>
    <div class="clear"></div>
    </div>
    
    <?php endif; ?>
    </div>
    
    <?php else : ?>
    <?php if ('open' == $post->comment_status) : ?>
    <p class="no"><?php _e('No comments yet.','lightword'); ?></p>
    <?php else : // comments are closed ?>
    <p class="no"><?php _e('Sorry, the comment form is closed at this time.','lightword'); ?></p>
    <?php endif; ?>
    <?php endif; ?>
    
    <?php if ('open' == $post->comment_status) : ?>
    comments<br />
    <br /><div id="respond">
    <h2 style="background:transparent;"><?php comment_form_title( __('Leave a comment', 'lightword'), 'Reply' ); ?></h2>
    comments<br />
    <?php if ( get_option('comment_registration') && !$user_ID ) : ?>
    <p><?php printf(__('You must be <a href="%s">logged in</a> to post a comment.','lightword'), get_option('siteurl')."/wp-login.php?redirect_to=".urlencode(get_permalink()));?></p>
    <?php else : ?>
    
    <form action="<?php bloginfo('wpurl'); ?>/wp-comments-post.php" method="post" id="commentform">
    <?php if ( $user_ID ) : ?>
    <p><?php printf(__('Logged in as %s.','lightword'), '<a href="'.get_option('siteurl').'/wp-admin/profile.php">'.$user_identity.'</a>'); ?> <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="<?php _e('Log out of this account','lightword') ?>"><?php _e('Log out &raquo;','lightword'); ?></a></p>
    
    <p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="1"></textarea></p>
    
    <?php else : ?>
    
    <p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="1"></textarea></p>
    <p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" />
    <label for="author"><small><?php _e('Name','lightword'); ?> <?php if ($req) _e('(required)','lightword'); ?></small></label></p>
    
    <p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" />
    <label for="email"><small><?php _e('Mail (will not be published)','lightword');?> <?php if ($req) _e('(required)','lightword'); ?></small></label></p>
    
    <p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
    <label for="url"><small><?php _e('Website','lightword'); ?></small></label></p>
    
    <?php endif; ?>
    
    <p><input name="submit" type="submit" id="submit" tabindex="4" accesskey="s" value="<?php echo attribute_escape(__('Submit','lightword')); ?>" /><?php cancel_comment_reply_link(__('( Cancel )', 'lightword')); ?><br class="clear"/></p>
    <?php comment_id_fields(); ?>
    <?php do_action('comment_form', $post->ID); ?>
    </form>
    <?php endif; ?>
    </div>
    <?php endif; ?>
    </div>
    
    <div class="tab-content">
    <?php if($trackbacks_nr == "0" && pings_open()) { echo "<p class=\"no\">"; ?><?php _e('No trackbacks yet.','lightword'); ?><?php echo "</p>"; } ?>
    <?php if(!pings_open()) { echo "<p class=\"no\">"; ?><?php _e('Trackbacks are disabled.','lightword'); ?><?php echo "</p>"; } ?>
    <?php foreach ($comments as $comment) : ?>
    <?php $comment_type = get_comment_type(); ?>
    <?php if($comment_type != 'comment') { ?>
    <div class="trackbacks"><?php comment_author_link() ?></div>
    <?php } ?>
    <?php endforeach; ?>
    </div>
    </div>

    I'm pulling my hair out trying to figure this out!!

    Any ideas?

    Thanks.

  19. Zoinks! Graphics
    Member
    Posted 3 years ago #

    Hey joefletcher, did you ever get a solution to your question about unchecking allow comments for pages in the admin while allowing them for posts? I too tried commenting out the comments code for pages, but somehow, even with that code NOT being there, spammers are still able to post comments if pages don't have "allow comments" deselected. I realize the "easy" answer is to either make the default not to allow comments and select for posts, OR deselect the allow for each page, but either way that's kind of a pain in the tuckus. Short of WP allowing separate comment settings for pages & posts, I'd think someone would've come up with a plugin or function to address this...? Bueller, Bueller...??

  20. wjm
    Member
    Posted 3 years ago #

    this is a missing feature in wordpress.
    i think under GENERAL SETTINGS >> COMMENTS
    there should be a default configuration option for pages only, not for pages and posts altogether.

    i am pretty sure withe a few line plugin, you will be able to change this.

  21. Zoinks! Graphics
    Member
    Posted 3 years ago #

    Thanks for understanding the need for this feature, wjm. I'm past my misspent days of hacking the WP core, so any changes to be made I'd prefer to do using a plugin or in my theme's functions.php file. Any ideas on how to achieve that?

  22. wjm
    Member
    Posted 3 years ago #

    i dont have the time right now.. but what could be done is

    1. a quick and dirty script
    when creating a page in the admin section, replace on the fly these wp_options: default_ping_status and default_comment_status to FALSE

    2. the configurable version
    add to /wp-admin/options-discussion.php the options, (under the default settings)
    * Allow trackbacks for pages
    * Allow comments for pages
    and when creating a page.. reading this values, and updating the chekboxes for alowing trackbacks and comments.

  23. eagerbob
    Member
    Posted 3 years ago #

    [removed by user]

  24. wjm
    Member
    Posted 3 years ago #

    news is this feature is already included in WP 3.0.

  25. djchuang
    Member
    Posted 3 years ago #

    @wjm - didn't see where this feature is included in WordPress 3.0 to to turn off comments for pages and turn on comments for posts by default. Help?

    (many of the solutions in this thread involved editing the PHP code and I am looking for a friendlier dashboard checkbox solution or plugin)

Topic Closed

This topic has been closed to new replies.

About this Topic