I wasn't exactly sure how to word the question, so I'm sure that's why I cannot find what I need when searching Google either.

I want to link all commenter names to their author.php page if they have edit_posts capability (Authors, Editors and Admins), otherwise link to the website they have listed in their profile.

I am not experienced with using comment_author.



Edited my answer since the original code was slightly flawed. Tested and triplechecked this to make sure it does exactly what you've requested. :)


function comment_author_profile_link(){

/* Get the comment author information */

global $comment;
$comment_ID = $comment->user_id;
$author = get_comment_author( $comment_ID );
$url = get_comment_author_url( $comment_ID );

/* Check if commenter is registered or not */
switch ($comment_ID == 0) {

case true: 
/* Unregistered commenter */    

    if ( empty( $url ) || 'http://' == $url )
        $return = $author;
        $return = "<a href='$url' rel='external nofollow' class='url' target='_blank'>$author</a>";


case false:
    /* Registered Commenter */      

    $registeredID = get_userdata($comment_ID);
    $authorName = $registeredID->display_name;
    $authorLevel = $registeredID->user_level;
    $authorURL = $registeredID->user_url;
    $authorID = $registeredID->ID;

        /* Check if they have edit posts capabilities & is author or higher */

    if ($authorLevel > 1 && user_can($authorID,'edit_posts') == true && count_user_posts($authorID) > 0) {
    /* Author+ with Posts */

    $return = '<a href="'.home_url().'/?author='.$authorID.'">'.$authorName.'</a>';

    } else {
    /* Below Author */

    if ( empty( $authorURL ) || 'http://' == $authorURL )
        $return = $authorName;
        $return = "<a href='$authorURL' rel='external nofollow' class='url' target='_blank'>$authorName</a>";



return $return;

add_filter('get_comment_author_link', 'comment_author_profile_link');
  • This code almost works. When pasted (as written) the commenter name for registered users is always displayed as "Anonymous". Also, I want ONLY registered users with edit_posts capability to link to the profile page. This is because I do not require registered users to fill out any profile info, however, Authors+ are required. I would rather send people straight to the commenters website, rather than an empty profile page. – Travis Pflanz May 5 '12 at 5:17
  • Fixed it now. Should be working as expected, @TravisPflanz – akamaozu May 5 '12 at 11:58
  • Beautiful! I will pay the bounty when it becomes available later this afternoon. – Travis Pflanz May 5 '12 at 13:52

protected by kaiser Feb 6 '14 at 12:18

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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