0

I have searched and searched, but not finding a solution to my situation.

I have a certain page where the user's avatar and display name are displayed. Currently these items are not clickable and do not link to anything, however I need them to link to the user's member profile when clicked.

Here is the code that is displaying the avatar + display name:

  $header .= "<div>".get_avatar($user_ID, 64)."</div>";
  $header .= "<div><strong>".__("Welcome", 'front-end-pm')." ". fep_get_userdata( $user_ID, 'display_name', 'id') ."</strong>";

The first line is displaying the avatar, the second line is displaying the username.

What needs to be done in order to make these items link to the user's profile page? (something like www.example.com/members/user would be the permalink location)

1

Use get_the_author_link() or get_the_author_meta('user_url', $user_id). Your code would become something like:

$author_link = get_the_author_link();
$header .= '<div><a href="'. $author_link . '">' .get_avatar($user_ID, 64).'</a></div>';
$header .= '<div><strong><a href="' . $author_link . '">' . __("", "front-end-pm").' '. fep_get_userdata($user_ID, 'display_name', 'id') .'</a></strong>';

Watch out with the quotes though, your code seems to use double quotes, I tried to replace it with single ones but you might have to check that in detail.

If this doesn't work, use $author_link = get_the_author_meta( 'user_url', 64 ); on the first line. This depends if you're inside the loop or not.

  • 1
    You are a genius and a lifesaver. You have no idea how many countless hours I spent trying to get this to work! Thank you SO much. Here is the code that works for me: $author_link = get_the_author_meta( 'user_url', 64 ); $header .= '<div><a href="http://example.com/users/user">' .get_avatar($user_ID, 64).'</a></div>'; $header .= '<div><strong><a href="http://example.com/users/user">' . __("", "front-end-pm").' '. fep_get_userdata($user_ID, 'display_name', 'id') .'</a></strong>'; – kosmicbird Oct 10 '16 at 23:03
  • I had to insert the specific a href permalink because it was only linking to the current page for some reason with ' . $author_link . ' as the href value (instead of user's profile). Only problem is that with me using that particular a href, the permalink shown at the bottom literally shows /users/user instead of /user/uniquedisplayname I can't thank you enough for your help. You rock! – kosmicbird Oct 10 '16 at 23:03
  • 1
    Would you consider marking my answer as accepted? Thanks! We've all been there, this site has been a lifesaver for me too sometimes! – Pim Oct 10 '16 at 23:16
  • Oh yes, sorry I just joined this site when I asked the question earlier and haven't gotten familiar with the interface yet. I was looking for a "resolved" button or something. How do I close it out? and thanks again soo much! – kosmicbird Oct 11 '16 at 2:47
  • Oh wait. Just saw the checkmark - does that accept the answer? Just pressed it to make it green :) If I need to do something else let me know! – kosmicbird Oct 11 '16 at 2:48

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.