get_comment_author_link

Retrieve the HTML link to the URL of the author of the current comment.

Description

(string) get_comment_author_link( (int) $comment_ID = 0 ); 

Both get_comment_author_url() and get_comment_author() rely on get_comment(), which falls back to the global comment variable if the $comment_ID argument is empty.

Returns (string)

The comment author name or HTML link for author's URL.

Parameters (1)

0. $comment_id — Optional. (int)
WP_Comment or the ID of the comment for which to get the author's link.

Usage

  1. if ( !function_exists( 'get_comment_author_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment-template.php'; 
  3.  
  4. // Optional. WP_Comment or the ID of the comment for which to get the author's link. 
  5. // Default current comment. 
  6. $comment_id = -1; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = get_comment_author_link($comment_id); 
  10.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment-template.php  
  1. function get_comment_author_link( $comment_ID = 0 ) { 
  2. $comment = get_comment( $comment_ID ); 
  3. $url = get_comment_author_url( $comment ); 
  4. $author = get_comment_author( $comment ); 
  5.  
  6. if ( empty( $url ) || 'http://' == $url ) 
  7. $return = $author; 
  8. else 
  9. $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>"; 
  10.  
  11. /** 
  12. * Filters the comment author's link for display. 
  13. * @since 1.5.0 
  14. * @since 4.1.0 The `$author` and `$comment_ID` parameters were added. 
  15. * @param string $return The HTML-formatted comment author link. 
  16. * Empty for an invalid URL. 
  17. * @param string $author The comment author's username. 
  18. * @param int $comment_ID The comment ID. 
  19. */ 
  20. return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID );