Is there a hook for comment author link?

The other two answers probably answer your question, but here’s a way look at WordPress source code to be able to determine for yourself whether a certain hook exists for your purposes.

You ask whether there is a hook for the comment author link. So let’s look at the source for that function: comment_author_link().

We see that there’s not really much to that function. It just echos the output of get_comment_author_link(). So let’s look at that function.

It does some stuff and then returns the filtered results of get_comment_author_link. So you could use that filter to modify the output of comment_author_link().

add_filter( 'get_comment_author_link', function( $return, $author, $comment_id ){
  if( 'example' === $author ) {
    $return = '<a href="https://example.com/">Example</a>';
  }
  return $return;
}, 10, 3 );

But I have a feeling that you want to modify the URL of the comment author. If that’s the case, we see that get_comment_author_link() calls get_comment_author_url() to determine the author.

And in that function we see that it returns the filtered results of get_comment_author_url.

So if you want to change the URL of the comment author link, you could do something like:

add_filter( 'get_comment_author_url', function( $url, $id, $comment ){
  if( 'example' === $comment->comment_author ) {
    $url="https://example.com/";
  }
  return $url;
}, 10, 3 );

Leave a Comment