WordPress: Hiding the comment link without disabling pings

I saw this question over on Holly Lisle’s weblog, and thought I’d try to help. After a number of posts eaten by the comment gnomes, I think I’ve found the answer.

Since this might be useful to someone else, I’ve decided to post it here.

In your WordPress template, find where you call comments_popup_link(). It probably looks something like this:

<?php comments_popup_link('No Comments', '1 Comment', '% Comments') ?> 

You want to replace that with something that looks like this:

<?php 
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 (($number != 0) || !('closed' == $post->comment_status)) { 
    commments_popup_link('No Comments', '1 Comment', '% Comments', 
                                        'comments-link',''); 
} 
?> 

Note: I’ve only tried this with WP 1.5+.

One thought on “WordPress: Hiding the comment link without disabling pings”

Comments are closed.