Title: Comments Enabled?  Hack
Last modified: August 18, 2016

---

# Comments Enabled? Hack

 *  pao
 * [22 years ago](https://wordpress.org/support/topic/comments-enabled-hack/)
 * I wanted to hide my comments links when comments were disabled on a post, so 
   wrote a quick (well, when you decide you should learn PHP to do the hack, it 
   takes a little longer) hack that can be used as a substitute for `comments_popup_link()`.`
   smart_comments_popup_link()`, which takes the same arguments as `comments_popup_link()`,
   only displays the link if comments are open or at least one comment has already
   been posted (and moderated, if that option is set). It differs from just setting
   the last argument of `comments_popup_link()` to ” because it depends only on 
   comments, not on trackbacks or pingbacks. There’s probably some room for improvement
   in this regard. Any advice for improvement (or actual improvements) will be appreciated,
   since I’m trying to learn.
    Add the following to the my-hacks.php file: `function
   smart_comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments',
   $CSSclass='', $none='Comments Off') { global $wpdb, $tableposts, $tablecomments,
   $id; $comments_enabled = $wpdb->get_results("SELECT comment_status FROM $tableposts
   WHERE id=$id"); $comments_exist = $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments
   WHERE comment_post_ID = $id AND comment_approved = '1'") > 0; if (($comments_enabled[
   0]->comment_status == 'open') || $comments_exist) { comments_popup_link($zero,
   $one, $more, $CSSclass, $none); } }

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter Anonymous
 * [22 years ago](https://wordpress.org/support/topic/comments-enabled-hack/#post-52397)
 * Incidentally, if anyone knows a better way of showing that code, please advise.
   I was going to put it up at the wiki, but I can’t seem to log into it to modify
   it.
 *  [eric](https://wordpress.org/support/users/eric/)
 * (@eric)
 * [22 years ago](https://wordpress.org/support/topic/comments-enabled-hack/#post-52403)
 * Most likely your problem with the wiki is because your user name is too short,
   it happened to others with short names and me as well even with 4 letters. Dunno
   why, but making up a longer user name seems to fix it.
 *  [pao](https://wordpress.org/support/users/pao/)
 * (@pao)
 * [22 years ago](https://wordpress.org/support/topic/comments-enabled-hack/#post-52699)
 * Now pluginized. See the wiki link in the post immediately above.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Comments Enabled? Hack’ is closed to new replies.

 * 3 replies
 * 3 participants
 * Last reply from: [pao](https://wordpress.org/support/users/pao/)
 * Last activity: [22 years ago](https://wordpress.org/support/topic/comments-enabled-hack/#post-52699)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
