Support » Installing WordPress » Can’t Completely Disable Comments

  • Resolved mrtoner


    I was looking here to figure out why my posts, which were set to disallow comments, still had a “0 Comments” link in the footer. I found this topic which indicated I could change the text for posts with comments disabled.

    However, when I added the none parameter the text did not change. Editing “0 Comments” to “No comments” changed the text. Also, clicking on the link took me to a comments page. Looking at the comments page, I see that everything after

    <dl id="comments-block">
    <?php if ( comments_open() ) : ?>

    is being displayed, so WP thinks that comments are open, even though “Allow Comments” is unchecked. Why would this be? BTW, I’m using the Minima Plus theme with WP 2.0.

Viewing 4 replies - 1 through 4 (of 4 total)
  • open up index.php in the /wp-content/yourtheme folder and delete the get_comment(); type php lines. that will do it for sure.

    Mark (podz)


    Support Maven

    mrtoner – you want to completely remove all comment posting?

    Delete comments.php
    Delete wp-comments.php
    and in index.php, remove this lot:

    <a class="comment-link" href="<?php the_permalink() ?>#comments"><em><?php comments_popup_link(__('0 Comments'), __('1 Comment'), __('% Comments')); ?></em><?php edit_post_link("edit", "|&nbsp;<em>", "</em>"); ?></a>

    <?php comments_template(); // Get wp-comments.php template ?>

    Let us know if that helps?

    @jwilliams: Yes, commenting out/deleting that line will drop off the comments, but the “0 Comments” text still remains. I don’t want to delete that text as well, since for some posts I want to enable comments, so I need to figure out why comments_popup_link() is returning the text for ‘zero’ when it should be returning the text for ‘none.’ (Where is this routine?)

    @podz: No, not all commenting.

    My mistake earlier: comments.php is working properly. The Comments RSS and Trackback links are the only items shown on the comments page, since they’re not explicitely excluded by <?php if ( comments_open() ) : ?>. It’s only the link text that is incorrect.

    Okay, I’ve managed to track this down myself. I found where comments_popup_link () is located: it’s (appropriately) in comment-functions.php. In my mind the script has a few bugs and I have changed it as described below:

    function comments_popup_link($zero='0 Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') {

    Here the function has defined some defaults, just in case your template left them out.

    global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb;
    global $comment_count_cache;

    if (! is_single() && ! is_page()) {
    if ( !isset($comment_count_cache[$id]) )
    $comment_count_cache[$id] = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';");

    $number = $comment_count_cache[$id];

    if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) {
    echo $none;

    Here WP checks to see if 1) there are no comments at this time, 2) “Allow Comments” is not checked, and 3) “Allow Pings” is not checked. If all three are true, WP echoes “Comments Off” — without a link — and returns. The problem here is that echo $none; was not in the original code, so with comments off nothing would appear. I think it’s a good idea to let users know what the comment status is if they’re used to seeing comment links.

    } else {
    if (!empty($post->post_password)) { // if there's a password
    if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
    echo('Enter your password to view comments');
    echo '<a href="';
    if ($wpcommentsjavascript) {
    if ( empty($wpcommentspopupfile) )
    $home = get_settings('home');
    $home = get_settings('siteurl');
    echo $home . '/' . $wpcommentspopupfile.'?comments_popup='.$id;
    echo '" onclick="wpopen(this.href); return false"';
    } else { // if comments_popup_script() is not in the template, display simple comment link
    if ( 0 == $number )
    echo get_permalink() . '#respond';
    echo '"';
    if (!empty($CSSclass)) {
    echo ' class="'.$CSSclass.'"';
    echo ' title="' . sprintf( __('Comment on %s'), $post->post_title ) .'">';
    comments_number($zero, $one, $more, $none, $number);

    Here’s where WP jumps to another function in comment-functions.php to insert the number of comments. I changed this line to add the $none parameter.

    echo '</a>';

    It was also necessary to fix comments_number ():

    function comments_number( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $none = 'Comments Off', $number = '' ) {

    I changed this line so the function would accept the $none parameter.

    global $id, $comment;
    $number = get_comments_number( $id );
    if ($number == 0) {
    if ( comments_open() ) {
    $blah = $zero;
    } else {
    $blah = $none;

    Here I added the else branch. Because it was missing, if the number of comments was zero the link would always read “0 Comments.” With this fix, if you have zero comments and commenting is off, you’ll see “Comments Off” (or whatever your template passes to comments_popup_link () ). If commenting is on and you have zero comments, you’ll still see “0 Comments.”

    } elseif ($number == 1) {
    $blah = $one;
    } elseif ($number > 1) {
    $blah = str_replace('%', $number, $more);
    echo apply_filters('comments_number', $blah);

    Of course, if you allow comments to begin with, add a few comments, and then disable comments, your comment links will still show the number of comments added before commenting was disabled.

    This should make your comment links display more accurately.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can’t Completely Disable Comments’ is closed to new replies.