WordPress: Remove author link in comments

  • Posted by M. Suleman Saeed Khan
  • at 9:54 AM -
  • 3 comments
wp comments WordPress: Remove author link in comments
WordPress, by default, display author name as a link to author URL in comments. It’s good for those who want to discuss seriously, they deserve backlinks for their websites. But sometimes you get spam comments, they just want to have backlinks without adding anything to discussion. To prevent this situation, removing author link in comments is a good way.


Remove author link in comments for WordPress 2.7 and newer

From WordPress 2.7, there is a function wp_list_comments() to display comments. It shows all commenter’s data, including link. In order to remove links, we need to change the way it display comments. We’ll do this by using callback function.
Open comments.php file of theme, find and replace function call:
  1. wp_list_comments();
with:
  1. wp_list_comments('callback=mytheme_comment');
This will replace the default function for displaying comments by our callback function – mytheme_comment. We will create this callback function in functions.php file of our theme. Open functions.php file and add the following code:
  1. function mytheme_comment($comment, $args, $depth) {
  2. $GLOBALS['comment'] = $comment; ?>
  3. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  4. <div id="comment-<?php comment_ID(); ?>">
  5. <div class="comment-author vcard">
  6. <?php echo get_avatar($comment,$size='48',$default='<path_to_url>' ); ?>
  7.  
  8. <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author()) ?>
  9. </div>
  10. <?php if ($comment->comment_approved == '0') : ?>
  11. <em><?php _e('Your comment is awaiting moderation.') ?></em>
  12. <br />
  13. <?php endif; ?>
  14.  
  15. <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),' ','') ?></div>
  16.  
  17. <?php comment_text() ?>
  18.  
  19. <div class="reply">
  20. <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  21. </div>
  22. </div>
  23. <?php
  24. }
You can realize that in the function mytheme_comment() above, the author link is replaced by author name, which is called by get_comment_author(). Note: this will display comments in default format, you might want to change it into your format to fit your theme.

Removing author link in comments for WordPress 2.6.x and older

In WordPress 2.6.x and older, there is no function wp_list_comments() for displaying comments automatically. We need to loop all comments, display each field of commenter’s data. It’s a bit easier for us to remove author link in comments in comparison with method above for WordPress 2.7 and newer, because all fields are clear and we don’t need to use callback function.
To do this, open comments.php file, find and replace:
  1. comment_author_link();
with:
  1. comment_author();

Removing URL box in comment form

All we’ve done above is preventing display author link in comments. But it is still in database. To prevent commenter to enter URL of his website, a good practice is removing URL box in comment form.
Open comments.php file, find form field to enter author URL, it looks like that:
  1. <p><label for="url">Website</label><input class="textfield" type="text" name="url" value="<?php echo $comment_author_url ?>" size="22"/></p>
All you need to do is just remove these lines, and URL box will disappear.
Replacing the author link by author name and removing the website URL form box is a good way to reduce very low quality real comments just for links. You know the sorts of comments where the author tells you it’s a great post, but adds nothing to the discussion and they just so happen to have a keyword rich author name for the link.

Author

Written by Admin

Hi! I am M. Suleman Saeed Khan. I am trying to give you useful information. Thanks

3 comments: