I am using this function

add_filter( 'get_comment_author_link', 'remove_comment_author_link', 10, 3 );
function remove_comment_author_link( $return, $author, $comment_ID ) {
   return $author;

to remove the users profile link from comments of a post.

I have been trying to use this filter but for removing the link only from subcribers users and not from everybody.

Any help would be appreciated.


This doesn't feel very nice since it calls get_comment() and get_userdata(), but I'm not sure there's an obvious better way since the code that calls this doesn't pass in the records we need:

function remove_comment_author_link( $return, $author, $comment_ID ) {
    $comment = get_comment( $comment_ID );

    if ( $comment && $comment->user_id ) {
        $user = get_userdata( $comment->user_id );

        if ( $user && $user->has_cap( "edit_posts" ) ) {
            // This user is contributor or better: show author link
            return $return;

    // Subscriber or not a blog user
    return $author;

and other functions have already made the exact same lookups and so the values will already be in wp_cache_get() for this page load.

I'm also using "edit_posts" to test if a user is better than subscriber: there may be better ways to do this too. (And I'm surprised we don't have to HTML-escape $author, but the existing get_author_comment_link() code doesn't.)

| improve this answer | |
  • Thank you for your help @Rup . It worked like a charm!! – Honoluluman May 11 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.