1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.1 Strip hyperlink from username

Discussion in 'Styling and Customization Questions' started by The Forum Heroes, Jun 29, 2013.

  1. The Forum Heroes

    The Forum Heroes Well-Known Member

    I can't find a way to do it. I want to strip the hyperlink from the poster's username making the username not clickable.
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    On which page?

    That will require editing all of the relevant templates.
     
  3. The Forum Heroes

    The Forum Heroes Well-Known Member

    Unless I can get the link to work correctly on the member card, I'd like to disable it site wide as I want to use facebook profiles as the site profile. On the membercard for the profile page link if i use facebook.com/{$fbUser.username} it links to your own account not the poster and using facebook.com/{$user} nothing happens.
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    For the most part, this can be achieved by editing the template helper...

    So XenForo usually produces a username via two ways:

    1) <xen:username tags
    2) {xen:helper username

    The <xen:username tag, interestingly enough, ultimately just calls the helper. So if you edit that helper, you pretty much affect almost everywhere a username appears.

    e.g. XenForo/Template/Helper/Core.php. Line 1663:
    PHP:
    return "<a{$href} class=\"username{$class}\"{$attribs}>{$username}</a>";
    Change it to:

    PHP:
    return "<span class=\"username{$class}\"{$attribs}>{$username}</span>";
    It will work for everywhere that uses the default tag/helper. This doesn't necessarily include everything. You will have to use a bit of leg work to discover which links aren't changed by this helper edit, but that should be quite a simple job for the most part.

    (Note, the line number above are correct as of XenForo 1.2 Beta 3)

    EDIT: You would need to look at modifying the avatar helper too as that links through to the profile. But it should be a similar process.
     
    SneakyDave and Brogan like this.
  5. The Forum Heroes

    The Forum Heroes Well-Known Member

    Thanks @Chris Deeming ! One other question. How can I get this to work? Anything I try, if I include the "{ }" the link is only facebook.com and if I only use $username it is facebook.com/$username not the username. I am forcing the FB username at sign up using $fbUser, so the URL will always be correct
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    This seems to work for me:

    PHP:
    return "<a href=\"http://facebook.com/{$username}\" class=\"{$class}\"{$attribs}>{$username}</a>";
    As I said in my edit, you would need to ensure you look at the helperAvatarHtml function too and modify that in a similar way. Note, I removed the username class (that's what triggers the member card JS).

    As for defining it in a normal template:

    <a href="http://www.facebook.com/{$user.username}">{$user.username}</a>
     
    The Forum Heroes likes this.
  7. The Forum Heroes

    The Forum Heroes Well-Known Member

    NM, figured my other question out. Works great Chris.. Now to just track down avatar linking
     
  8. The Forum Heroes

    The Forum Heroes Well-Known Member

  9. The Forum Heroes

    The Forum Heroes Well-Known Member

    This worked perfect! I added a target to it so they don't leave my site via clicking the link

    PHP:
    return "<a href=\"https://facebook.com/{$username}\" target=\"new\" class=\"{$class}\"{$attribs}>{$username}</a>";
     
    Chris D likes this.
  10. The Forum Heroes

    The Forum Heroes Well-Known Member

    Perfect! Found where to edit avatar's too, changed it to return "<span and they are no longer clickable! Thanks again Chris!
     
    Chris D likes this.
  11. The Forum Heroes

    The Forum Heroes Well-Known Member

    Revisiting for some code changes. Maybe you have a solution @Chris Deeming.

    So instead of forcing FB username as I orginally planned, I decided to allow them to choose their own name and use auth id to link to them on facebook

    So I changed the code to

    Code:
    return "<a href=\"https://facebook.com/{$user['facebook_auth_id']}\" target=\"new\" class=\"{$class}\"{$attribs}>{$username}</a>";
    and it works in message info.. But in threads. if you goto https://www.blizzardhq.com/forums/main-forum.2/ the username link is only facebook.com
     
  12. Chris D

    Chris D XenForo Developer Staff Member

    This can happen.

    More than likely the fetch thread query doesn't join onto the xf_user_profile table which is where the facebook_auth_id is kept.
     
  13. The Forum Heroes

    The Forum Heroes Well-Known Member

    Is there a way to make the username unlinkable there yet clickable in the message info? Or will I need to use <span> instead and just make the avatar the link?
     

Share This Page