WordPress: Remove author link in 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:

wp_list_comments();

with:

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:

function mytheme_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
   <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
     <div id="comment-<?php comment_ID(); ?>">
      <div class="comment-author vcard">
         <?php echo get_avatar($comment,$size='48',$default='<path_to_url>' ); ?>

         <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author()) ?>
      </div>
      <?php if ($comment->comment_approved == '0') : ?>
         <em><?php _e('Your comment is awaiting moderation.') ?></em>
         <br />
      <?php endif; ?>

      <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>

      <?php comment_text() ?>

      <div class="reply">
         <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
      </div>
     </div>
<?php
        }

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:

comment_author_link();

with:

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:

<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.

🔥 HOT: Interested in boosting your WordPress SEO? My Slim SEO plugin is a super lighweight and automated plugin that handles most the hard work for you: meta tags, sitemap, redirection, schema & link building.

👉 Have a look and you will love it: wpslimseo.com

Leave a Reply

Your email address will not be published. Required fields are marked *


Copyright © 2024 Deluxe Blog Tips. All rights reserved.

My products: Meta Box | Slim SEO